I am new to robot framework.
I want to know how can i remove all white spaces after the string .
My string is "OTP Hello
"
I want all spaces and line break after Hello to get deleted
How can I achieve it?
Use the Strip String keyword in the Strings library, and specify mode=right, to remove the whitespace only from the right side. Sample:
${src}= Set Variable OTP Hello${SPACE}\n
Log To Console The source: ---${src}---
${stripped}= Strip String ${src} mode=right
Log To Console The result: ---${stripped}---
The output will be:
The source: ---OTP Hello
---
The result: ---OTP Hello---
Related
simple question that I hope has a simple answer
I want to store a formatted string to pass later to function call. I would like to have line breaks baked into one long string rather than send a string for each line. So for example
b = f'hello \n world'
b
this gives me 'hello \n world' which is not what I want.
How can I do this in a compact manner. I would prefer to avoid joins or something like that with a newline separator.
Thanks in advance.
I am trying to manipulate string so it capitalizes each word after any delimiter.
Currently, I am using capwords() method imported from string module. Code sample:
my_string = "hello MY-naMe-is john"
new_string = string.capwords(my_string)
print(new_string)
Using only capwords() method, result is this:
Hello My-name-is John
Result that I am trying to get:
Hello My-Name-Is John
Is it possible to use more than one separator in capwords()? Is there a solution to this while still using capwords() method? Thanks!
Use title() in built method
my_string = "hello MY-naMe-is john"
new_string = my_string.title()
print(new_string)
#'Hello My-Name-Is John'
There is no way to use capwords and get the result that you need. The capwords(s, sep=None) documentation shows the steps that it undergoes:
str.split() - here the sep is used (if provided)
str.capitalize() - first character of each item in the list (from split) is capitalized
str.join() - the string is joined back
split takes just one sep. However, re.split takes multiple delimeters/separators.
Use title() if you want to achieve your desired result, as suggested by #Ananth.P
I am trying to clean text strings containing any ' or ' (which includes an ; but if i add it here you will see just ' again. Because the the ANSI is also encoded by stackoverflow. The string content contains ' and when it does there is an error.
when i insert the string to my database i get this error:
psycopg2.ProgrammingError: syntax error at or near "s"
LINE 1: ...tment and has commenced a search for mr. whitnell's
the original string looks like this:
...a search for mr. whitnell's...
To remove the ' and ' ; I use:
stripped_content = stringcontent.replace("'","")
stripped_content = stringcontent.replace("' ;","")
any advice is welcome, best regards
When you try to replace("' ;","") it literally searching for "' ;" occurrences in string. You need to convert "' ;" to its character equivalent. Try this:
s = "That's how we 'roll"
r = s.replace(chr(int('''[2:])), "")
and with this chr(int('''[2:])) you'll get ' character.
Output:
Thats how we roll
Note
If you try to run this s.replace(chr(int('''[2:])), "") without saving your result in variable then your original string would not be affected.
I need to import text from txt file with some variables. I use BufferedReader and File Reader. In code I have :
String car = "vw golf";
String color = "nice sunny blue color";
And in my txt file:
I have nice " +car+ " which has "+color+".
My expected output :
I have nice vw golf which has nice sunny blue color.
My actual output is :
I have nice " +car+ " which has "+color+".
If I've understood correctly, what you want to do is replace " + car + " with the value of your car string and likewise for colour. You've tried to do this by writing your text file as if it were a command to be evaluated. However, that won't happen - it will just be outputted as is. I'm going to assume you are using c#. What you need to do is, prior to outputting your string, parse it to replace the markers with the variables. I would recommend you get rid of the double quotes in your text file. You could then do something like this:
string text = this.ReadTextFromFile();
string ammended = text.Replace("+car+", car);
As mentioned, this is assuming you remove the double quotes from your text file so it reads:
I have nice +car+ which has +color+.
Also, you don't need to use the + symbols, but I suppose they are a good way of designating a unique token to be replaced. You could use {car} in the file and then likewise in the Replace startment, for example.
I may not have properly understood what you wanted to do, of course!
Edit: Incase of confustion,
this.ReadTextFile();
was just a short hand way of saying that the text variable contains the contents as read from your text file.
I wrote the following line:
string QuoteTest2 = "Benjamin Netnayahu,\"BB\", said that: \"Israel will not fall\"";
This example went well, but what can I do in case I want to write a multi paragraph string including quotes?
The following example shows that puting '#' before the doesn't cut it..
string QuoteTest2 = #"Benjamin Netnayahu,\"BB\", said that: \"Israel will not fall\"";
The string ends and the second quote and the over just gives me errors, what should I do?
Use double quotes to escape ""
e.g.
string QuoteTest2 = #"Benjamin Netnayahu,""BB"", said that: ""Israel will not fall""";