How to Replace only whole word in ASP.net using c#
-
Here I want to replace string. e.g My string is "Add new message in newthing" here I want to replace "new".But when I used string.replace then it replaces "newthing" also.In short I want to replace whole word. Swapnil Bhavsar
-
Here I want to replace string. e.g My string is "Add new message in newthing" here I want to replace "new".But when I used string.replace then it replaces "newthing" also.In short I want to replace whole word. Swapnil Bhavsar
Do the replacement using a regular expression for the word, where you add the word boundary code before and after the word: theNewString = new RegEx("\\b" + RegEx.Escape(theWord) + "\\b").Replace(theString, theReplacement);
--- It's amazing to see how much work some people will go through just to avoid a little bit of work.