string x = "I am a hunter, what do i do. <Name> is a good boy. His age is <Age> and a <occupation> of <Institute>. \n\n He is passionate about his <passion> and also a hardworking fellow. <WifeName> is his wife and she is a sweet girl, She loves her husband a lot. Her age is <WifeAge> and <occupation> of <Institute>";
This text dosen’t mean anything. but what i have to do is to replace all “<” with “<b>” and all “>” with “</b>“, all “\n\n” with “<br/>“.
I tried to use :
string y = replace(replace(x,"<","<b>"),">","</b>");
this led me to a devastating result. I think you all can guess, what happened. Now I am searching for a easy and simple solution for this replacement. I wish, I could make this clear.
So if I understand correctly, you use “
<” to denote “Start bold” and “>” to denote “End bold”.Using a composite call to
String.Replaceobviously isn’t going to work because<is used in the replacement token which is matched by the next call.One approach is to do the replacement as you encounter it and write it to a new string, like so: