Site Meter Asp.Net-Csharp,Asp,Ado.Net,Ado,Micosoft,Visualstudio,Visual webgui: Substring in,c#

Saturday, November 14, 2009

Substring in,c#

To find the last character in a string
string lastCharacter = myString.Substring(myString.Length - 1, 1);
//i.e. the last character is a SubString of myString, one character long, starting one character short of the length of myString

To remove the last two characters of a string
string myNewString = myString.Substring(0, myString.Length - 2);
//i.e. the new string is a SubString 2 characters shorter than myString, starting at the beginning of myString

No comments:

Post a Comment