1.Substring
Substring(startIndex);
- startIndex
- Type: System.Int32
The zero-based starting character position of a substring in this instance.
string str="ABCDEFG";
str.Substring(2); // returns "CDEFG"
str.Substring(7);//returns an empty string
str.Substring(8);//Causes an ArgumentOutOfRangeException
Substring(startIndex,length);
- startIndex
- Type: System.Int32
The zero-based starting character position of a substring in this instance.
- length
- Type: System.Int32
The number of characters in the substring. - str.Substring(2,1); // returns "C"
str.Substring(7,0);//returns an empty string
str.Substring(8,1);//This throws ArgumentOutOfRangeException
2.LastIndexOf
value
- Type: System.String
The string to seek. - string str="<b>This is bold text</b>";
- int endTagStartPosition = item.LastIndexOf("</"); // Remove the identified section, if it is valid.
- if (endTagStartPosition >= 0 ) item = item.Substring(0, endTagStartPosition);
- int openTagEndPosition = item.IndexOf(">"); // Remove the identified section, if it is valid.
- if (openTagEndPosition >= 0) item = item.Substring(openTagEndPosition + 1);
- Console.WriteLine("str: " + item); //This is bold text