String replace

Tyron199

Member
Joined
Apr 16, 2009
Messages
9
Programming Experience
3-5
Hey, Im having some trouble with string replace.

I have a body of text that contains tags like #CSV1 #CSV2 etc usually up to #CSV25, now I have to replace each tag with other text.

Everything works fine up to #CSV9 after that it reads #CSV10 as if it is #CSV1 and not 10, how can I tell it to only replace exact matches.

How can I tell it to only replace exact matches, should I use regex or what?
 
How about you do the replacements backwards, so #CSV10 has already been replaced when it comes time to replace #CSV1? The alternative would be to use Regex.Replace but I don't see any advantage to doing that unless going backwards is not possible.
 
That solved my problem, thanks.
I am still wondering how you can tell the string replace method to only replace exact matches
 
That solved my problem, thanks.
I am still wondering how you can tell the string replace method to only replace exact matches
You can't. For that you'd have to use Regex.Replace.
 
Back
Top