How to split strings from a line in robot framework - robotframework

How to get rest of the values from the variable
${random employee}= Convert To String ${random emp}
${replace}= Remove String Using Regexp ${random employee} ['\\[\\]\\,]
${splitline}= Fetch From Left ${replace} ${SPACE}
Output:
${replace} Alagu kartest1234+3alagu#gmail.cokartest1234+3ramu#gmail.com Developer Team B3 Team lead
${splitline} = Alagu
How to get rest of the values from the variable ${replace}

Keyword Split String from String standard library does this.
Split String string, separator=None, max_split=-1
Splits the string using separator as a delimiter string.
If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored.
Split words are returned as a list. If the optional max_split is given, at most max_split splits are done, and the returned list will have maximum max_split + 1 elements.
Examples:
#{words} = Split String ${string}
#{words} = Split String ${string} ,${SPACE}
To get single values from #{words} use common array syntax: #{NAME}[i]. i is the index of the selected value. Indexes start from zero.

Related

How to replace the single quote ( ' ) into double quotes ( " ) in Robot Framework?

I have a List, items are created by append by a Loop. I want to use this list as a json. The problem is that the items of that list use the single quote so it can't be the json.
Get Order Items
[Tags] Get Order Items
Set Headers ${HEADER CUSTOMER}
GET ${ORDER GET BY CODE ENDPOINT}/${ORDER CODE}
Integer response status 200
${NUMBER OF ITEMS} Output $.number_of_items
${NUMBER OF ITEMS} Evaluate ${NUMBER OF ITEMS} + 1
${ORDER ITEMS} Create List
:FOR ${i} IN RANGE 1 ${NUMBER OF ITEMS}
\ Append To List ${ORDER ITEMS} ${ORDER CODE}${i}
Set Global Variable ${ORDER ITEMS}
Actual result: ['N19072596HB1', 'N19072596HB2', 'N19072596HB3', 'N19072596HB4', 'N19072596HB5']
Expected result: ["N19072596HB1", "N19072596HB2", "N19072596HB3", "N19072596HB4", "N19072596HB5"]
This: ['N19072596HB1', 'N19072596HB2', 'N19072596HB3', 'N19072596HB4', 'N19072596HB5'] , is python's string representation of a list, and they have picked to use single quotes for it.
As your end goal is to use the double-quoted version in a json, the best bet is to use the python's json library to convert it for you, instead of replacing single with double quotes:
${list as string}= Evaluate json.dumps($ORDER_ITEMS) json
(note how the variable is not surrounded by curly brackets - thus you're passing the actual variable to the method, not its value)
Why not to use a simple string replacement?
Because you don't want to deal with cases where a list member may have a quote, single or double - like ['N19072596HB1', "N1907'2596HB2", 'N19072596HB1', 'N19072"596HB2'].
A trivial string replace will fail miserably, while the json library is designed to handle these cases as expected.

How to make a pattern that uses the formula and the value of the same cell in Google Sheets?

I want to create a model where I can add numbers to that specific column and it will return a string concatenating a string and the value put in the cell.
Example:
When writing a value 123 to the cell, it will return a string say "http:// www.link.com/" concatenated with the value of the value 123 (as string).
Resulting -> http:// www.link.com/123
Use the operand &
For example, use this formula the result cell:
="http:// ww.link.com/"&A1
It will use A1 cell value to concatenate to your string

How do I create a function to check if a string only consists of A-Z , 0-9

Is there any way to check in Xquery (A Xquery function) if an input string has only characters A-Z or numbers 0-9 and no other characters.
for example if the string is ABZ10 the function should return true and if the input string is 5& 123x it returns a false.
I am able to do it in java by simply using following.
inputstring.matches("^[0-9A-Z]+$"))
Use:
matches($vYourString, '^[A-Z0-9]+$')

Regex: Split X length words

I'm new to regular expresions. I have a gigantic text. In the aplication, i need words of 4 characters and delete the rest. The text is in spanish. So far, I can select 4 char length words but i still need to delete the rest.
This is my regular expression
\s(\w{3,3}[a-zA-ZáéíóúäëïöüñÑ])\s
How can i get all words with 4 letters in asp.net vb?
/(?:\A|(?<=\P{L}))(\p{L}{4})(?:(?=\P{L})|\z)/g
Explanation:
Switch /g is for repeatedly search
\A is start of the string (not start of line)
\p{L} matches a single code point in the category letter
\P{L} matches a single code point not in the category letter
{n} specify a specific amount of repetition [n is number]
\z is end of string (not end of line)
| is logic OR operator
(?<=) is lookbehind
(?=) is lookahead
(?:) is non backreference grouping
() is backreference grouping
Using the character class provided above in another answer (\w does NOT match spanish word characters unfortunately).
You can use this for a match (it matches the reverse, basically matches everything that is NOT a 4-character word, so you can replace with " ", leaving only the 4-character words):
/(^|(?<=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W)))(.*?)((?=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W))|$)/gis
Approximated code in VB (not tested):
Dim input As String = "This is your text"
Dim pattern As String = "/(^|(?<=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W)))(.*?)((?=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W))|$)/gis"
Dim replacement As String = " "
Dim rgx As New Regex(pattern)
Dim result As String = rgx.Replace(input, replacement)
Console.WriteLine("Original String: {0}", input)
Console.WriteLine("Replacement String: {0}", result)
You can see the result of the regex in action here:
http://regexr.com?30n29
\[^a-zA-ZáéíóúäëïöüñÑ][a-zA-ZáéíóúäëïöüñÑ]{4}[^a-zA-ZáéíóúäëïöüñÑ]\g
Translated:
A non-letter, followed by 4 letters, followed by a non-letter. The 'g' indicated will match globally ... more than once.
Check out this link to find out more info on looping over your matches:
http://osherove.com/blog/2003/5/12/practical-parsing-using-groups-in-regular-expressions.html

last occurrence of a string in a string in flex

Is there any inbuild function to find out the last occurrence of a string pattern in a string in action script .
Yes, check out the lastIndexOf method of the String object.
PS. If by string pattern you mean a regular expression rather than a literal string, you could use the match method instead, passing a RegExp and setting the g (global) flag; then you could check the last match in the returned result.

Resources