Remove last Digits

studio
variable

#1

Hi,

I would like to please about help or advice. I got array of string:

And on the end of all phrases i got number… how to recognize and remove this digits… solution must be dynamic because the length of string are changing.

Regards
@fudi5


#2

I’m not sure exactly what you are wanting, but you can look maybe online for a Regex pattern that will extract only the numbers that end a string.

It might be a pattern like this: “[0-9]{1,2}$”, which says a number 1-2 digits that ends the string ($)

To use the pattern, you can do something like the below:

System.Text.RegularExpressions.Regex.Match( text, "[0-9]{1,2}$").Value

Hope that helps.

Regards.


#3

You need to remove the last digit alone ? or need to eliminate after reaching some length?

(yourString.TrimEnd().Substring(0, yourString.Length - 1) will remove the last character


#4

Hi @karthick

So cut last character is not a solution… look on pictures… one time you got “1.1” next time only “2.” other line got 2.1 it must be removed.

@ClaytonM thx mate ill try this solution.

Regards
@fudi5


#5

Hi @fudi5,

strinput=System.Text.RegularExpressions.Regex.Replace(strinput,"\d*[.]$|\d*[.] \d*$","")

Regards,
Arivu


#6

Then follow @ClaytonM procedure and replace it using Regex.


#7

Since you need the decimal, you might also try @arivu96’s

which basically says to extract ending number with decimal on end OR ending number with decimal and another number.