How to convert Float to String in robotframework - robotframework

have a list with data as float or number and I need to convert it to String for comparison with robotframework with another dataset which is in String only.
I tried string operations from robotframework but I didn't find anything to convert float to String.

There is a Builtin keyword that does just that - Convert To String, that will make any passed value to a string type.

There is not always need to make conversions.
All of these assertions below work fine:
${float}= Convert To Number 4.22
${string}= Convert To String 4.22
Should Be Equal '${float}' '${string}'
Should Be Equal As Strings ${float} ${string}
Should Be Equal As Numbers ${float} ${string}

Related

How to always get a leading 0 in robot framework DateTime

I am currently trying to figure out how to always get a leading 0 when getting current date time.
The following is the way I am currently doing it:
${date} = Get Current Date result_format=datetime
${dateyear}= Convert To String ${date.year}
${datemonth}= Convert To String ${date.month}
${dateday}= Convert To String ${date.day}
${datehour}= Convert to string ${date.hour}
${dateminute}= Convert to string ${date.minute}
The problem is that when I get date.day/minute/hour/, I get back 1-9 instead of 01-09. I am using the values to enrich a json, which expects 2 characters for each, so passing 1 results in an error, while passing 01 will work fine.
You can use zfill() function to pad strings:
${dateminute}= Set Variable 5
${dateminute}= Evaluate '${dateminute}'.zfill(2)

Malformed string from character string

I have a simple character string:
y <- "Location 433900E 387200N, Lat 53.381 Lon -1.490, 131 metres amsl"
When I perform regex capture on it:
stringr::str_extract(r'Lat(.*?)\,', y)
I get this error:
>Error: malformed raw string literal at line 1
why?
With R's raw strings (introduced in version 4.0.0), you need to use either ( or [ or { with the quotes, e.g.,
r'{Lat(.*?)\,}'
This is documented at ?Quotes (and in the release notes):
Raw character constants are also available using a syntax similar to the one used in C++: r"(...)" with ... any character sequence, except that it must not contain the closing sequence )"⁠. The delimiter pairs [] and {} can also be used, and R can be used in place of r."

How to convert any type into String in Julia

Using Julia, I'd like to reliably convert any type into type String. There seems to be two ways to do the conversion in v0.5, either the string function or String constructor. The problem is that you need to choose the right one depending upon the input type.
For example, typeof(string(1)) evaluates to String, but String(1) throws an error. On the other hand, typeof(string(SubString{String}("a"))) evaluates to Substring{String}, which is not a subtype of String. We instead need to do String(SubString{String}("a")).
So it seems the only reliable way to convert any input x to type String is via the construct:
String(string(x))
which feels a bit cumbersome.
Am I missing something here?
You should rarely need to explicitly convert to String. Note that even if your type definitions have String fields, or if your arrays have concrete element type String, you can still rely on implicit conversion.
For instance, here are examples of implicit conversion:
type TestType
field::String
end
obj = TestType(split("x y")[1]) # construct TestType with a SubString
obj.field # the String "x"
obj.field = SubString("Hello", 1, 3) # assign a SubString
obj.field # the String "Hel"

How to get a count of number of occurrence of a substring in a string in teradata?

I have a column in a teradata table with string values like "page1-->page2-->page1-->page3-->page1--page2-->..."
I want to search for a specific page and get the number of occurrence of the page in the string. I couldn't find any function that gives this result.
There's no builtin function, but there's a common solution:
Remove all occurences of the substring from the string and compare the length before/after:
(Char_Length(string) - Char_Length(OReplace(string, searchstr))) / Char_Length(searchstr)
Edit:
For a wildcard search you can utilize REGEXP_REPLACE:
Char_Length(RegExp_Replace(RegExp_Replace(s, 'page1(.+?)page3', '#',1,0), '[^#]','',1,0))
For `#' use a character which is known not to be in your input string.

ColdFusion: Integer "0" doesn't convert to ASCII character

I have a string (comprised of a userID and a date/time stamp), which I then encrypt using ColdFusion's Encrypt(inputString, myKey, "Blowfish/ECB/PKCS5Padding", "Hex").
In order to interface with a 3d party I have to then perform the following:
Convert each character pair within the resultant string into a HEX value.
HEX values are then represented as integers.
Resultant integers are then output as ASCII characters.
All the ASCII characters combine to form a Bytestring.
Bytestring is then converted to Base64.
Base64 is URL encoded and finally sent off (phew!)
It all works seamlessly, APART FROM when the original cfEncrypted string contains a "00".
The HEX value 00 translates as the integer (via function InputBaseN) 0 which then refuses to translate correctly into an ASCII character!
The resultant Bytestring (and therefore url string) is messed up and the 3d party is unable to decipher it.
It's worth mentioning that I do declare: <cfcontent type="text/html; charset=iso-8859-1"> at the top of the page.
Is there any way to correctly output 00 as ASCII? Could I avoid having "00" within the original encrypted string? Any help would be greatly appreciated :)
I'm pretty sure ColdFusion (and the Java underneath) use a null-terminated string type. This means that every string contains one and only one asc(0) char, which is the string terminator. If you try to insert an asc(0) into a string, CF is erroring because you are trying to create a malformed string element.
I'm not sure what the end solution is. I would play around with toBinary() and toString(), and talk to your 3rd party vendor about workarounds like sending the raw hex values or similar.
Actually there is a very easy solution. The credit card company who is processing your request needs you to convert it to lower case letters of hex. The only characters processed are :,-,0-9 do a if else and convert them manually into a string.

Resources