I have a string of “Please bill 28kg” or sometimes “Bill 28lbs” or many more potential type of string that I would receive.
So now the question is how do I just strip out the numeric characters only from the string.
String - “Bill 28kg”
Expecting outcome - “28”
Do anyone have any idea how to do this? I’ve tried Regex, but not sure how to do it as the output is in list of array.
string b= System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"\D","")
It will replace all the characters other than digits and return only digits.
The code is really a good one. Unfortunately if the string contain “Please bill 28.4 kg”. It returns as “284”. Meaning to say it also strip out the decimal points. Can anycome please assist me on this?
I got it Mahesh, I’ve used [A-z]+ and it works
I have similar case. I want to extract just the amount.
However my case is the amount appears: Balance Due CHF2,335.00.
I need to take care of the comma and decimal.
So using above the decimal , comma changes into *, the output appear as *233500
Try like this
string b = System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"[^/./,0-9]","")
similar case i have .
if my input is like: 2345 ref number on 2.2.18
the output should get only 2345
can you help on this ?
input.Split(" "c)(0).toString will give your result.
HI … thanks for the reply and even i have found out one solution using regex (\D)([0-9])(.)*