INPUT : There's string that numbers, and a string, dots and spaces. Notice that e
defines a the separator between the numbers.
e.27.3.90.. .e 3.50 2.30..e2.0.1.2. .50..
OUTPUT : I want to remove all the spaces and those extra dots except for the one that makes up following and add a ,
before e
,
,e273.90,e3502.30,e2012.50
Best catch was this How to remove extra decimal points?. But it's based on Javascript
parseFloat()
.
I also saw this post : Convert to valid decimal data type. But that's in terms of SQL
and pretty much using multiple replace()
.
PS: There are so many posts regarding regex
in various kind. I tried to build one, but seems like no success so far.
regex
or ideas.regex
vs multiple replace()
Here is the code I have been gasping ;)..:
List<string> myList;
string s = "";
string s2 = "";
string str = "e.27.3.90..bl% .e 3.50 2.30. #rp.e2.0.1.2..50..y*x";
s = Regex.Replace(str, @"\b[a-df-z',\s]+", "");
myList = new List<string>(Regex.Split(s, @"[e]"));
Last str
is your result
string str = "e.27.3.90..bl% .e 3.50 2.30. #rp.e2.0.1.2..50..y*x";
str = Regex.Replace(str, "[^e^0-9]", "");
str = Regex.Replace(str, "([0-9]{2}?)(e|$)", ".$1,$2");
//str = "," + str.Substring(0, str.Length - 1);