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:

enter image description here

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

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -