How to remove the value of the last position of the TextBox with the Substring?

2

How to remove the value of the last position from TextBox with Substring ?

Suppose TextBox gets a value with this mascara = 0.00% , however, I just want to save the numbers, not the percent, how do I do it?

    
asked by anonymous 02.10.2017 / 16:04

2 answers

3

Assuming that really only the last % , that nothing was typed wrong, and usually something can be, a lot can go wrong if it is not as expected, and validate everything work, that would be it: p>

texto = texto.TrimEnd('%');

If you want the latter, it does not matter what:

texto = texto.Substring(0, texto.Length - 1);
    
02.10.2017 / 16:07
2

You can also use Replace to remove some sign or character from your String.

Let's suppose:

String texto = "0,00%";

// Retirando o sinal de porcentagem
texto = texto.Replace("%","");
Resultado: 0,00

// Retirando a virgula
texto = texto.Replace(",","");
Resultado; 000%

//retirando a virgula e o sinal de porcentagem
texto = texto.Replace("%","").Replace(",","");
Resultado: 000

The Replace switch is between the first two quotation marks so it is between the last two quotes = .Replace ( "first" , )

You can use Replace multiple times in a chained string in the same string.

    
03.10.2017 / 04:04