Friday, March 12, 2010

String Manipulations

// Concatenation of the strings.
string start = "This is a ";
string end = "concatenated string";
string result= start + end;

// Inserting Strings into Strings
string first= "Please check this code.";
string second= "understand";
Console.WriteLine(first.Insert(24, second));

// Search and Replace
string sample = "The good programming.";
string result = sample.Replace("good", "excellent"));

// Copying Strings
string myString= "The ultimate programming code.";
string result = string.Copy(myString);

// Extracting Text from a String
string sample = "The quick start tutorial is a must.";
string result = sample.Substring(4); //result will be "quick start tutorial is a must."

//Trim Function
string myString= " String Manipulation " ;
string Result= Name.Trim(); //it will remove the starting and ending space of the string.

// Remove specified number of characters from string
string myString= "The String Manipulation";
string Result= MainString.Remove(1,4);

No comments: