String.Substring Method

Expand
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
8 out of 14 rated this helpful - Rate this topic
.NET Framework Class Library

String.Substring Method

Retrieves a substring from this instance.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method Substring(Int32) Retrieves a substring from this instance. The substring starts at a specified character position.
Public method Substring(Int32, Int32) Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
Top
Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
String.Substring
As the name indicates String.Substring returns sub string from the main string.

e.g.

string str = "Microsoft Community";
string strNew = str.subString(10);        //        strNew will be "Community"
strNew = str.subString(0,9);                 //        strNew will be "Microsoft" - here 9 is length of characters.

Please note that Substring uses a zero indexing i.e. in above example letter 'M' is at zero position.

8/22/2011
Index limits
The specified start position can be at the end of the string but not beyond.

string str = "abc";
string a2 = str.Substring(2); // returns "c"
string a3 = str.Substring(3); // returns an empty string
string a4 = str.Substring(4); // Causes an ArgumentOutOfRangeException
11/15/2010