Get non numeric values from string value c# -
i have value below
string value = "11,.ad23"; int n; bool isnumeric = int.tryparse(value, out n);
i control if string numeric or not.if string not numeric , has non numeric need get non numeric values below
result must below
,.ad
how can in c# ?
if doesn't matter if non-digits consecutive, it's simple:
string nonnumericvalue = string.concat(value.where(c => !char.isdigit(c)));
online demo: http://ideone.com/cromht
if use .net 3.5. mentioned in comment there no overload of string.concat
(or string.join
in dmytris answer) takes ienumerable<string>
, need create array:
string nonnumericvalue = string.concat(value.where(c => !char.isdigit(c)).toarray());
that takes non-digits. if instead want take middle part, skip digits, take until the next digits:
string nonnumericvalue = string.concat(value.skipwhile(char.isdigit) .takewhile(c => !char.isdigit(c)));
Comments
Post a Comment