Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string replacing - C#

Tags:

string

c#

Say I have a string containing numbers and other chars.

I want to reduce the string to numbers only.

F.e. from 23232-2222-d23231 to 23232222223231

Can this be done with string.replace()?

if not, what's the simplest and shortest way?

10x!

like image 744
user181218 Avatar asked Jul 05 '26 11:07

user181218


1 Answers

There are a bunch of possibilities, from Regular Expressions to handling the text yourself. I'd go for this:

Regex.Replace(input, @"\D+", "")
like image 189
Lucero Avatar answered Jul 07 '26 00:07

Lucero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!