Sarah_Tang
(Sarah Tang)
October 29, 2021, 9:37pm
1
hello,
i have strings like this
(* 10.00_)
(* 22,000_)
Desired output
10.00
22000
I need to keep the decimal if it is there. RIght now, i am doing replace with the expression “\D” -Regex.Replace(x.Field(Of Object)(“Ext amount”).ToString,“\D”,“”)
However, when there is a decimal such as 10.00, it gives me the value 1000.
Thanks in advance
ppr
(Peter Preuss)
October 29, 2021, 10:00pm
2
@Sarah_Tang
give a try on
and refer on groups
(\d+\.?)(?:\,?)(\d+)
As an alternate: catch also comma and replace it afterwards
>Regex.Matches("(* 10.00_) (* 22,000_)","[\d,.]+").Cast(Of Match).Select(Function (m) m.Value.Replace(",","")).toArray
<- string[2] { "10.00", "22000" }
Following your direction for replacing the unwanted you can try:
For some additional starter help have a look here:
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…