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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -