c# - Change in string some part, but without one part - where are numbers -
for example have such string:
ex250-r-ninja-08-10r_
how change such string?
ex250 r ninja 08-10r_
as can see change - space, didn't change have xx-xx
part... how such string replacement in c# ? (also string different length)
i -
string correctstring = errstring.replace("-", " ");
but how left - number pattern xx-xx ?
you can use regular expressions perform substitutions in cases. in case, want perform substitution if either side of dash non-digit. that's not quite simple might be, can use:
string replacesomehyphens(string input) { string result = regex.replace(input, @"(\d)-", "${1} "); result = regex.replace(result, @"-(\d)", " ${1}"); return result; }
it's possible there's more cunning way in single regular expression, suspect more complicated :)
Comments
Post a Comment