Trim end og string?

Hi folks, I have trouble with TrimEnd.
I have a string where last character should be %
I want to remove text after the las time in string where % is.
Tried with myString.TrimEnd("%“c) and myString.TrimEnd(”%"c).toString, but I can not remove the text after %

regards

1 Like

TrimEnd will remove % if it is available at the end. It will not remove other text.

For example
Text = ABCdef%%%
and if you use TreimEnd("%") output would be --> ABCdef

Text = ABCdef%%%abc
Output would be ABCdef%%%abc (Same as input as it not ending with %)

1 Like

To Get Text before % you can use

output = text.split("%".ToChar)(0)

1 Like

Hi @kare.smorvik, you can also try regex, where the pattern could be e.g. “(.+%)” - please see the below test results, where you are getting rid of the part after the last %:

this expression would help you do that
if this is the input string
str_input = "123% asdf23123"

then
str_output = Split(str_input,"%")(0).ToString.Trim+"%"
so the output will be like this
str_output = “123%”

Cheers @kare.smorvik

Thanks, this works for me, and I can use it to manupulate other parts of string to.

Cheers @kare.smorvik

Just one question Sir. How would this one look like if you want to splitt beween to argument like:
Split(str_input,"%","!")(0).ToString.Trim+"%"

We need to mention as two different expression buddy as the split method can take only one delimiter argument
Cheers @kare.smorvik

Hi, realised that this remove text after the first % so I loose everything after. Only want to remove end of string after last%.
If string is like abcde%fghij%klmno%pqr. Only want to trim %qpr and keep last % so output looks ltke this: abcde%fghij%klmno%

regatds

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