by
0
5
4,564
156
Top 1% !
Popular
Famous
Specified
Refined
Popularity: 2178th place
Created
Modified Oct 1, 2013
This snippet is Public
No tags for this snippet yet.
.NETFramework4.0
Architecturex86_64
InputName0stringToSearch
InputName1find
InputName2replace
InputType0string
InputType1string
InputType2string
LanguageCSharp
LicenseMIT_X11
MethodNameReplaceExactWord
OSWindows
OutputTypestring
Windows VersionWindows7

Replace just an exact word in C#

Same as String.Replace but with case-insensitive matches and search for the exact word.
E.g. searching in "Java and Javascript with Java." the word 'Java', and replacing it with 'Python' results in "Python and Javascript with Python."
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/11287/Replace-just-an-exact-word-in-C-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static string ReplaceExactWord(this string stringToSearch, string find, string replace) { string pattern = @"\b" + find + @"\b"; return Regex.Replace(stringToSearch, pattern, replace, RegexOptions.IgnoreCase); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus