The first index position is zero.


Substring(int startPos) 
Substring(int startPos, int length)

Retrieves a substring from this instance. The substring starts at a specified character position.
An index is the position of a character within a string, and is counted starting from the first character in the string.

string myText = "abcdefg" 

// remove the first character
myText.Substring(1); // "bcdefg"

// remove the last character
myText.Substring(0, myText.Length - 1); // "abcdef"

// return the first character
myText.Substring(0, 1); // "a"

// return the last character
myText.Substring(myText.Length - 1); // "g"
myText.Substring(myText.Length - 1, 1); // "g"


IndexOf(string value) 
IndexOf(string value, int startPos)

Returns the index of the first occurrence of a String, or one or more characters, within this instance.
The IndexOf method is case sensitive
This returns -1 if the substring does not exist !!

string myText = "01/03/2004"; 
myText.IndexOf("/") = 2
myText.Substring(0, sSomeText.IndexOf("/")); // "01"

string myText = "EUR (25)"; 
string myCurrency = myText.SubString(0, myText, myText.IndexOf("(");
string myNumber = myText.SubString(myText.IndexOf("("));

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext