Hi,
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.
Example:
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.
4 Likes
MAHESH1
(MAHESHKUMAR JV)
February 28, 2018, 7:18am
2
@Serran_Neru
try this
string b= System.Text.RegularExpressions.Regex.Replace(“string_Variable”,“\D”,“”)
It will replace all the characters other than digits and return only digits.
Regards,
Mahesh
28 Likes
Hi Mahesh,
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?
Regards,
Serran
I got it Mahesh, I’ve used [A-z]+ and it works
4 Likes
Mallika
(Mallika Banerjee)
July 23, 2018, 12:42pm
6
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 *2 335 00
MAHESH1
(MAHESHKUMAR JV)
July 23, 2018, 1:33pm
7
@Mallika
Try like this
string b = System.Text.RegularExpressions.Regex.Replace(“string_Variable”,“[^/./,0-9]”,“”)
Regards,
Mahesh
7 Likes
Uthraa
October 5, 2018, 12:57pm
9
hi @MAHESH1
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.
3 Likes
Uthraa
October 8, 2018, 5:27am
11
HI … thanks for the reply and even i have found out one solution using regex (\D )([0-9])(. ) *
3 Likes