Trim or substring

studio
string

#1

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.


Moving specific content in notepad or word pad to Datatable
#2

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


#3

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.


#4

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).


#5

Thanks andrzej.kniola
It worked!

Best regards.


#6

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:


#7

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


Extract values using Substring
#8

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


#9

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”.


#10

Hi Srikanth,

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

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


#11

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!!


#12

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


#13

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


#14

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


#15

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


#16

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);


#17

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


#18

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.


#19

try with this

var x = yourstrvar.IndexOf("\n")

Regards…!!
Aksh


#20

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