Essential C# String Manipulation  Suggest an edit

Replacing a string within a string

Using the System.String.Replace method, you can replace part of a string with another string.

string s = "Hello World";
s = s.Replace("World", "Universe"); // s = "Hello Universe"

All the occurrences of the search string are replaced:

string s = "Hello World";
s = s.Replace("l", "L"); // s = "HeLLo WorLD"

String.Replace can also be used to remove part of a string, by specifying an empty string as the replacement value:

string s = "Hello World";
s = s.Replace("ell", String.Empty); // s = "Ho World"

Table Of Contents
14 String Manipulation
22 Enum
25 GUID
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close