Filter a string

Hi,

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!

Hi,
Here we go.
filterString.xaml (7.3 KB)

1 Like

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())

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

Regards…!!
Aksh

2 Likes

yes, this works!! Thanks a lot both!