Replacing substring
In this chapter you will learn:
Replace substring
Replace method from string type replaces the found substring with specified string.
using System;/*from j a v a 2s. co m*/
class Sample
{
public static void Main()
{
string s = "java2s.com";
s = s.Replace("java", "JAVA");
Console.WriteLine(s);
}
}
The output:
Replace characters
using System; /*from j a v a 2s . c o m*/
class MainClass {
public static void Main() {
string str = "This is a test";
Console.WriteLine("Original string: " + str);
// Replace characters
str = str.Replace('a', 'X');
Console.WriteLine(str);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » String