Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple string replace question in C#

Tags:

c#

.net

I need to replace all occurrences of \b with <b> and all occurrences of \b0 with </b> in the following example:

The quick \b brown fox\b0 jumps over the \b lazy dog\b0.
. Thanks
like image 797
FadelMS Avatar asked Dec 28 '22 17:12

FadelMS


1 Answers

Regular expressions is massive overkill for this (and it often is). A simple:

string replace = text.Replace(@"\b0", "</b>")
                     .Replace(@"\b", "<b>");

will suffice.

like image 100
jason Avatar answered Dec 30 '22 09:12

jason