c# - Split on numeric to letters excluding comma -
i have string containing "0,35ma" have code below, splits "0,35ma" into
"0"
","
"35"
"ma"
list<string> splittedstring = new list<string>(); foreach (string stritem in strlist) { splittedstring.addrange(regex.matches(stritem, @"\d+|\d+") .cast<match>() .select(m => m.value) .tolist()); } what want code splitted into
"0,35"
"ma"
how achieve this?
it looks want tokenize string numbers , else.
a better regex approach split number matching pattern while wrapping whole pattern capturing group matching parts resulting array.
since have , decimal separator, may use
var results = regex.split(s, @"([-+]?[0-9]*,?[0-9]+(?:[ee][-+]?[0-9]+)?)") .where(x => !string.isnullorempty(x)) .tolist(); see regex demo:
the regex based on pattern described in matching floating point numbers regular expression.
the .where(x => !string.isnullorempty(x)) necessary rid of empty items (if any).

Comments
Post a Comment