Trim or substring

hello everybody

i’m new in uipath and a have a question.
i need to use a trim or substring formulas in a string for this case:
old string: 10.01 / 01.01 / 01.10
new string: 10.1 / 1.1 / 1.10

how can I do this?

Best regards.

1 Like

newS = oldS.Replace("01","1")

7 Likes

Hello badita

I just need to remove the leading zeros…

Examples: 10.01 → new 10.1
01.01 → new 1.1

I made a substring for to get variable1 → 10 and variable2 → 01. I need remove only leading zero.
the expected result is variable1 + “.” + variable2 = 10.1

Tks.

If you have it separated already, you can use .TrimStart:
newS = oldS.TrimStart({"0"c})

Sidenote: the c is to tell the interpreter that the “0” string should be treated as a char. { } are for array initializers (since it only accepts a char array, not single chars).

8 Likes

Thanks andrzej.kniola
It worked!

Best regards.

Hi Folks!!

i would like to use this post to make a question to you, if you allow to me.
i have a a string like 123456_F1 and i need to trim the three last chars , but i don’t know how.
The string could be not the same i.e. 1234567891234_F3, this is the reason why i need to trim the three last chars.
i’ll hope it will not disturb in this post.:sweat_smile:

To remove last three characters from string you can use string.Substring(Int32, Int32) and give it the starting index 0 and end index three less then the string length. It will get the substring before last three characters.

myString = myString.Substring(0, str.Length-3);

it retrieves a substring from this instance. The substring starts at a specified character position

You can also using String.Remove(Int32) method to remove the last three characters by passing start index as length - 3, it will remove from this point to end of string.

myString = myString.Remove(myString.Length-3);

String.Substring Method (Int32, Int32)
String.Remove Method (Int32)

Or

If you wants to remove the all text after “" character the also first you can find the position of "” character in the string(using string.indexof(“_”)) then you can use the string.substring with that position length

if there will be multiple “" character in string then you can use string.Lastindexof("”) to find the last postion of that character.

For your reference to find the position and remove the rest text please see the attached sample workflow:

Remove_strin_after_underscore.xaml (7.0 KB)

Regards…!!
Aksh

10 Likes

Thank you for ur help Aksh!!! :wink::+1:

Hi #andrzej.kniola can you tell me how to trim the URL from the following string

" there could me many,but this is one http://www.w3schools.com/"

The above one which is quoted is a string which is stored in “StrVariable”. Now I want to extract only the URL into “StrURL”.

Hi Srikanth,

if your string always contains “http” then you can use this in assign.

StURL = StrVariable.Substring(StrVariable.IndexOf(“http”))

2 Likes

HI Akash, I am new to prgramming so need your help, How we can remove special character from an string.

String is *English, I want to remove * from begining and want only English.

Your help will be much appreciated!!

Hey @Saurabh_Sahu

You can use any of one from below:

String data = "*English";
data.Remove(0,1);
data.TrimStart("*"C);
data.Substring(1);

Regards…!!
AKsh

2 Likes

@aksh1yadav -Hi it worked but it made a space in begining of string, I don’t want any space too.

Hey @Saurabh_Sahu

check this with two write line it will give you correct thing

"*English".Length.ToString // in first line which will give you length = 8

"*English".Remove(0,1).Length.ToString // in second write line activity and this will give you length = 7

Regards…!!
AKsh

1 Like

@aksh1yadav-Not worked for me,*English is just an example, I have to do it for any string which contains * in start.

Yes but it will work for all if there is no space exists you can try first to trim it

like data.trim.Remove(0,1)

but in this you can use

data.TrimStart("*"C);

1 Like

@aksh1yadav-Hey it work now.Thanks so much!!

Hi Aksh1, in continuation to this topic, if you can please advise, how i can get the indexof value/Position whenever this is new line in the sentence?

For example my string is:
“Color : Red
Some random content, and some more.
And more”.

My task is to extract Red, i am not able to get the position for the new line/end of the statement.

Thank you.

try with this

var x = yourstrvar.IndexOf(“\n”)

Regards…!!
Aksh

No, it gives -1.
Do you suggest any other alternative?