PART II
C h a p t e r 2 2 :
S t r i n g s a n d F o r m a t t i n g
683
Here is an example that demonstrates
Insert( )
,
Remove( )
, and
Replace( )
:
// Inserting, replacing, and removing.
using System;
class InsRepRevDemo {
static void Main() {
string str = "This test";
Console.WriteLine("Original string: " + str);
// Insert
str = str.Insert(5, "is a ");
Console.WriteLine(str);
// Replace string
str = str.Replace("is", "was");
Console.WriteLine(str);
// Replace characters
str = str.Replace('a', 'X');
Console.WriteLine(str);
// Remove
str = str.Remove(4, 5);
Console.WriteLine(str);
}
}
The output is shown here:
Original string: This test
This is a test
Thwas was a test
ThwXs wXs X test
ThwX X test
Do'stlaringiz bilan baham: |