Marcelo, you've had a similar case here ( See this answer from Maniero ).
In this case, the AP asked that if the character was typed repeated, that repetition would be ignored as well.
Following the same logic of this answer, your case 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.
At the end, the result is passed to the variable saida
.
Alternatively, using Linq
would look like this:
var saida2 = new string(texto.Where(c => char.IsDigit(c)).ToArray());
These two examples have already been adapted are available for testing on .Net Fiddle , explore there.