How to remove invalid characters from a string

I am trying to change a program on Windows CE 5.0 that scans a barcode for dates. What is the best way to output an invalid string from a date format

Example:

2014/03/12 --> 20140312
2014.03.12 --> 20140312
2014-03-12 --> 20140312

I want to automatically delete these lines (/, - ,.)

Thank!

+4
source share
2 answers

Using:

Regex.Replace("2014/03/12", "[^0-9]", string.Empty)
+7
source

Another method:

string s = "2014/03/12";
s = s.Replace('/').Replace('.').Replace('-');

See here for more details .

Note: this approach is suitable for a limited number of characters, for more complex string manipulations you will want to use Regex

+1
source

Source: https://habr.com/ru/post/1531261/


All Articles