Filter a string



I just cannot find the answer anywhere. I would have to filter a string so that it would contain only digits. Example: “1234gg?” should become “1234”.
I’ve tried string.Replace("![0-9]","") and some other ways to do it, but it doesn’t work.
How would you do this, any ideas? Thanks in advance!


Here we go.
filterString.xaml (7.3 KB)


Hey @bluerock

Use this Regex

String input_str_data = “1234gg?”;

Regex.Replace( input_str_data, “[^0-9]+”, string.Empty)

on more way to use linq

String number_str = new String( input_str_data.ToCharArray().Where(function(c) char.IsDigit(c)).ToArray())

Note:- To use linq you have to import System.Linq and System.Linq.Expressions namespaces if they have not inclueded.



yes, this works!! Thanks a lot both!