Marcelo, here you had a similar case (Look at this response from Maniero).
In this case, the AP requested that if the character had been typed again, this repetition would also be ignored.
Following the same logic of this answer, your Cap would look like this:
var texto = "Abcc111de12234";
var lista = new char[texto.Length];
for (int i = 0, j = 0; i < texto.Length; i++)
if (char.IsDigit(texto[i]))
lista[j++] = texto[i];
var saida = new string(lista);
Basically, logic is reading the input (texto
) and traversing each character of that input, discarding what is not a digit (number).
In the end, the result is passed to the variable saida
.
Another alternative, using Linq
would be so:
var saida2 = new string(texto.Where(c => char.IsDigit(c)).ToArray());
These two examples already adapted are available for testing on . Net Fiddle, explores there.
I believe that in this question you have the answer: https://answall.com/questions/123453/remover-characters- n%C3%A3o-num%C3%A9ricos-de-uma-string. Possible duplicate.
– Jonathan Barcela