Chrome browser takes \n\t\r etc

Hi All,

In IE, the replace string was working fine and it replaces\n \r \tab etc

But when I use the same code for chrome browser,it doesn’t eliminate those chars

Please help

Thanks
Teenu

Could you please provide more details? Where are you replacing? Activity used etc.

I am getting string from UI and use an Assign activity

ExceptionMsg=DiffMsg.ToString.Replace(“Begin calculating operations to be performed”,"").Replace(“Finished calculating operations to be performed”,"").Replace(“Diff Messages”,"").Replace(“Diff Calculation Completed Successfully”,"").Replace(Environment.NewLine,"").ToString

where DiffMsg will have the entire string. In chrome browser ExceptionMsg has the value “\n\n\t\r…” so its not going to empty condition.

Possible white space characters are \r \n \t \f \v
You should add them also to the replace conditions.

Another option is to use regular expression.

pattern = "\\r|\\n|\\t|\\f|\\v|[\r\n\t\f\v]"
ExceptionMsg = Regex.Replace(ExceptionMsg, pattern, "")

Ok I will try with the above format and let you know.

I tried replacing with white space chars but it was not working, May be the format i give was wrong. Thanks!

The problem is when you get text from Chrome \r \n etc are literal. Means, it does not represent new line tab etc. So your pattern should escape the \. So to replace them we have to use pattern like \\n.

The pattern I provided takes care of both literal characters and white spaces.

pattern = "\\r|\\n|\\t|\\f|\\v|[\r\n\t\f\v]"

You can also use ‘@’
pattern = @"\r|\n|\t|\f|\v|[\r\n\t\f\v] as its .net,c#

A verbatim string is one that does not need to be escaped, like a filename:

string myFileName = "C:\\myfolder\\myfile.txt";

can be written as

string myFileName = @"C:\myfolder\myfile.txt";

The @ symbol means to read that string literally, and don’t interpret control characters otherwise.

UiPath has not yet started supporting C#. Also, in this case, we need both escaped and non escaped characters to be 100% sure. For instance \n will handle any new lines and \\n will handle any literal \n in the string.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim

Hey @Teenu

Try with

.Replace(vbCr, "").Replace(vbLf, "").Replace(vbCrLf, "")

Regards…!!
Aksh

1 Like

Thank you Aksh,it worked almost fine, but I still not get it empty as the result is " " (It should be just “”)

DiffMsg.ToString.Replace(“Begin calculating operations to be performed”,"").Replace(“Finished calculating operations to be performed”,"").Replace(“Diff Messages”,"").Replace(“Diff Calculation Completed Successfully”,"").Replace(Environment.NewLine,"").Replace(vbCr, “”).Replace(vbLf, “”).Replace(vbCrLf, “”).Replace(vbTab,"").ToString

Do a final trim. Just wanted to know, what are you trying to achieve with this?

if the extracted message is an empty string-I just need to cancel the process by clicking a button

Doing a Final trim worked fine. Thanks Kannan

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.