How to remove trim in string in Uipath

Hi everyone, i have string like that:
strValue=“2016

3

(12)”
Now i wanna change to “2016年3月(12)”
Can you tell me how to change that?

Hi,

Can you try the following?

strValue.Replace(chr(13),"").Replace(chr(10),"")

OR

System.Text.RegularExpressions.Regex.Replace(strValue,"\s","")

Regards,

1 Like

Thanks, it worked

1 Like

Hi @Phuong_Bui ,

Try the below solution.

system.Text.RegularExpressions.Regex.Replace(STR, "\s*", "")

@Yoichi , i loved the regex expression you provided. the solution you provided will work !.
If it helps, just small update on the expression i.e. If we add the (i.e. "\s*"), it will help us replace 0 or more whitespaces

Regards,
Pavithra

1 Like

Hi @pavithra_pavi ,

I think “\s*” is not very good because it matches 0 whitespace. For example, the following expression shows which part is replaced by pattern “\s*”.

system.Text.RegularExpressions.Regex.Replace(STR, "\s*", "x")

So the pattern "\s+" or just "\s" i posted previously is better, i think.

Regards,

Hi @Yoichi ,

Thank you for the explanation. i understand it now why you didnt used *. However i have a question, When we say *, it replaces 0 or more, which means even if there is no whitespaces, it wouldn’t impact anything am i right? or am i missing something here?

I tried using \s*, for a string “robot” , to test on 0 or more character, I didn’t face any error. The output remain same as input. and for string “robot master”, the output i received is “robotmaster”.

So can you please help me to understand when we need to use * and +

Hi,

Yes you’re right. The both result are same. but \s* will takes just a little bit longer in theory. Basically, we can know which quantifier should be used from considering which character(s)/position will be matched by the pattern and possible values for the input string.

Regards,

1 Like

Ohh!!!, Got it. Thanks a lot for clear explanation. Moving onwards, i will keep this in mind whenever i need to perform string operation

1 Like