I have some string which is being created programmatically as part of a GitHub action. The contents of the string are coming from an API so I don't know how long each part of the string will be. I then need to tweet the string using Twitter.jl. However, right now it errors out sometimes since the string is too long (twitter has a 280 character limit).
How can I check the length of the string in Julia to make sure it is less than 280 characters?
Julia has a build in length function which returns the length of a given string like the following example:
julia> a = "Hello world"
"Hello world"
julia> length(a)
11
Related
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}
I built a script in R that automatically create a very long and complex SQL query to create a view over similar tables of 5 databases.
Of course there were integration issues to solve. The only one remaining to make this happen is the problem I am going to present you now.
Considering one very long string like
'"/*NOTES*/", "/*TABLE_ID*/", "/*TABLE_SUB_ID*/", "/*TABLE_SUB_SUB_ID*/", "OTHER_COLUMNS",'
My objective is to replace
this string '"/*' with this string '/*'
this string '*/",' with this string '*/'
I tried with:
gsub('"/*', '/*', '"/*NOTES*/", "/*TABLE_ID*/", "/*TABLE_SUB_ID*/", "/*TABLE_SUB_SUB_ID*/", "OTHER_COLUMNS",')
but it returns the string
'/**NOTES*//*, /**TABLE_ID*//*, /**TABLE_SUB_ID*//*, /**TABLE_SUB_SUB_ID*//*, /*OTHER_COLUMNS/*,'
whereas my expected output is the following string:
'/*NOTES*/ /*TABLE_ID*/ /*TABLE_SUB_ID*/ /*TABLE_SUB_SUB_ID*/ "OTHER_COLUMNS",'
Note the * is not escaped but it represents start (/*) and end (*/) of comments when the string will be run by a SQL compiler
Escaping regexes requires two backslashes, so the following will get you what you want:
gsub('"?(/\\*|\\*/)"?', '\\1', '"/*NOTES*/", "/*TABLE_ID*/", "/*TABLE_SUB_ID*/", "/*TABLE_SUB_SUB_ID*/", "OTHER_COLUMNS",')
# [1] "/*NOTES*/, /*TABLE_ID*/, /*TABLE_SUB_ID*/, /*TABLE_SUB_SUB_ID*/, \"OTHER_COLUMNS\","
FYI, double-backslashes are required for most, but the following are legitimate single-backslash special characters:
'\a\b\f\n\r\t\v'
# [1] "\a\b\f\n\r\t\v"
'\u0101' # unicode, numbers are variable
# [1] "a"
'\x0A' # hex, hex-numbers are variable
# [1] "\n"
Perhaps there are more, I didn't find the authoritative list though I'm sure it's in there somewhere.
I am encrypting the plain text using RSA and converting that value to base64 string.But while decrypting the I altered the base64 string and try to decrypt it...it given me same original text return.
Is there any thing wrong ?
Original Plain Text :007189562312
Output Base64 string : VfZN7WXwVz7Rrxb+W08u9F0N9Yt52DUnfCOrF6eltK3tzUUYw7KgvY3C8c+XER5nk6yfQFI9qChAes/czWOjKzIRMUTgGPjPPBfAwUjCv4Acodg7F0+EwPkdnV7Pu7jmQtp4IMgGaNpZpt33DgV5AJYj3Uze0A3w7wSQ6/tIgL4=
Altered Base64 String : VfZN7WXwVz7Rrxb+W08u9F0N9Yt52DUnfCOrF6eltK3tzUUYw7KgvY3C8c+XER5nk6yfQFI9qChAes/czWOjKzIRMUTgGPjPPBfAwUjCv4Acodg7F0+EwPkdnV7Pu7jmQtp4IMgGaNpZpt33DgV5AJYj3Uze0A3w7wSQ6/tIgL4=55
Please explain. Thank you.
I'm assuming you're asking whether the altered ciphertext should have thrown an error when decrypting. It looks like the altered string only adds two characters to the end and is otherwise the same string.
Your Base 64 library probably makes some reasonable assumptions when parsing Base 64 data. Base 64 works by encoding 3 bytes into 4 characters. If at the end the data length is not a multiple of 3 it must be padded. That is signalized by the = at the end of the encoded string.
This also means that during parsing, the library knows that padding characters are at the end and stops parsing there. If the alteration appeared at the end of the string then the encoded ciphertext didn't effectively change.
I have a parser written in PLY that has the following token definition
def t_COMMAND(t):
r'create|show'
return t
def t_SCOPE(t):
r'user|domain'
return t
def t_STRING(t):
r'[a-zA-Z_#\*\.]*'
return t
I am trying to parse the following string
show user where created_on = foo
Here is my grammar
S:COMMAND SCOPE FILTER;
FILTER:WHERE EXP |;
EXP:STRING OP STRING
...
I get a syntax error at the created_on token, probably because it gets matched as a COMMAND rather than STRING
Is there a way to make PLY take the largest possible match?
Found two possible approaches
User a reserved words tuple and append it with the token list as in Specification of tokens
If possible, add quotes to the STRING as '[a-zA-Z_#\*\.]*', so that it can be distinguished from COMMAND
I chose the second approach, as I have a lot of so called reserved words.
I am updating some asp and vb code and have a string which I need to count the number of characters in. part of the string has non-English characters. Using len() does give the number of characters, it gives the length of the string, and because some of the characters are not in english the len() function does not work.
For example len("abc")=3 but len("אבג") is 6. The len() of the combined string is 9.
Is there a function or another way that would calculate the number of characters?
I found out the problem - if you save an asp page in as UTF-8 then the len() function does not work - it gives you double the number of actual characters, for non-English characters only - see example in the question.
To avoid this problem save the asp page in UTF-8 +BOM and then the len() function works correctly in all cases.