Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System
String Class
Methods
Substring Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
String.Substring Method

Retrieves a substring from this instance.

Overload List

Retrieves a substring from this instance. The substring starts at a specified character position.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Substring(Integer) As String
[C#] public string Substring(int);
[C++] public: String* Substring(int);
[JScript] public function Substring(int) : String;

Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Substring(Integer, Integer) As String
[C#] public string Substring(int, int);
[C++] public: String* Substring(int, int);
[JScript] public function Substring(int, int) : String;

Example

[Visual Basic] 
Dim myString As String = "abc"
Dim test1 As Boolean = String.Compare(myString.Substring(2, 1), "c") = 0 ' This is true.
myString.Substring(3, 1) ' This throws ArgumentOutOfRangeException.
Dim test2 As Boolean = String.Compare(myString.Substring(3, 0), String.Empty) = 0 ' This is true.

[C#] 
String myString = "abc";
bool test1 = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1); // This throws ArgumentOutOfRangeException.
bool test2 = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.

[C++] 

String *myString = L"abc";
bool test1 = String::Compare(myString->Substring(2,1), L"c") == 0;  // This is true.
myString->Substring(3,1);  // This throws ArgumentOutOfRangeException.
bool test2 = String::Compare(myString->Substring(3,0), String::Empty) == 0;  // This is true.

[JScript] 
var myString : String = "abc";
var test1 : boolean = String.Compare(myString.Substring(2, 1), "c") == 0; // This is true.
myString.Substring(3, 1);  // This throws ArgumentOutOfRangeException.
var test2 : boolean = String.Compare(myString.Substring(3, 0), String.Empty) == 0; // This is true.

See Also

String Class | String Members | System Namespace

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker