How to manipulate a part of string: Split, Trim, Substring, Replace, Remove, Left, Right

Yah Correct
Cheers @caduque

2 Likes

Hi @Adrian_Star

I moved your post to the #news:faq section, it’s great!

I suppose it could only use some better formatting, currently I think you simply copy pasted the text from other source and it looks a bit awkward :smiley:

5 Likes

Hey, I’m putting graphics for a better understanding of the subject.

Moved to first entry.

13 Likes

Does anyone know how to remove the symbol " in a text? I tried

str_paymentpartner.Replace(“”“,”")

but doesn’t seems to work :sweat_smile: :weary:

1 Like

@Nasya.Idris Please check below one.

str_paymentpartner.Replace(“”“”,“”)

3 Likes

You can use logic:

output = System.Text.RegularExpressions.Regex.Replace(your_String, "[^\w\.@-]","")

or

output = System.Text.RegularExpressions.Regex.Replace(yourString, "[^\w\.@-]"," ")

regex

Or read this post:
Replace (regex) problems

9 Likes

Thank you!

4 Likes

bravo and I hope this gets added to some of the official documentation/ reference in academy. bump for visibility

6 Likes

Amazing! This is as if good for documentation in UiPath. I wish the UiPath Academy would also add some in-depth tutorials like this one for addressing specific functionalities in their courses. Great job @Adrian_Star!

7 Likes

Você esta de Parabéns!!!

2 Likes

This is amazing! Thank you so much for this.

3 Likes

Thank you very much man. You definitely simplified everything.

3 Likes

Thank you for your efforts, its quite helpful.

1 Like

Hi @Adrian,

How can we remove a blank line after our text? I’ve tried with “Trim” but without success.

My text is:
Client ID: PU23971
Client Name: Chance Strittmatter
Client Country: Germany

And I want the string “PU23971-Chance Strittmatter-Germany”

I’m using those methods:
ClientID = Trim(Split((Split(ClientInformation,"Client ID: ")(1).ToString),"Client Name: ")(0)).ToString
ClientName= Trim(Split((Split(ClientInformation,"Client Name: ")(1).ToString),"Client Country: “)(0)).ToString
ClientCountry = Trim(ClientInformation.Split(”:"c)(3))

Type into: ClientID + “-” + ClientName + “-” + ClientCountry

But I’m having this:

image :sob:

1 Like

Hi @Airun, You can try:

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

Remove New Line from whole string:

Replace(vbCr, "")- removes \r [CR (Carriage Return)]
Replace(vbLf, "") - removes \n [LF (Line Feed, Environment.NewLine)]
Replace(vbCrLf, "") - removes \r\n [CR+LF ( End Of Line)]

Remove New Line only from the end of string:

textString.TrimEnd(vbCr.ToCharArray)
textString.TrimEnd(vbCrLf.ToCharArray)
textString.TrimEnd(vbCrLf.ToCharArray)

7 Likes

Perfect!!! Thank you very much!!! :star_struck: :partying_face:

image

2 Likes

Hello,
In this video I do a lot of stuff with String:

0:35 Examples for Substring functions
4:10 IndexOf and LastIndexOf
5:00 SubString working together IndexOf and LastIndexOf
6:45 Split string by character
8:50 Split string by string
12:00 Lower Case and Upper Case
12:45 Trim
15:05 Compare strings in multiple ways
19:05 Resume of all the String function part

Thanks,
Cristian Negulescu

6 Likes

thank you for the wonderful gifts

1 Like

how can I use substring in order to check keywords in the first 100 characters of email body. I tried to use it as - item.Body.Substring(0,100).Contains(“stop”)
however, I am getting an error for it.

HI, apparently your Body email is not always 100 characters long. You can first measure the length of a string with?:
item.Body.Lenght (as Int 32 variable), and then substitute a variable containing the length of characters under the limit substring.
if lenght >= 100
then
item.Body.Substring(0,100).ToLower.Contains("stop")
else
item.Body.Substring(0,len).ToLower.Contains("stop")

Something like this:

The simpler solution I see is to put assign with item.Body.Substring (0,100) .Contains (“stop”) in try catch. in catch you just give something like: item.Body.Contains (“stop”) just without substring.

Something like this:
image

2 Likes