Public Function Substring ( _ startIndex As Integer, _ length As Integer _ ) As String
Dim instance As String Dim startIndex As Integer Dim length As Integer Dim returnValue As String returnValue = instance.Substring(startIndex, length)
public string Substring ( int startIndex, int length )
public: String^ Substring ( int startIndex, int length )
public String Substring ( int startIndex, int length )
public function Substring ( startIndex : int, length : int ) : String
子字串的起始索引。
子字串中的字元數。
ArgumentOutOfRangeException
startIndex 加上 length 指示不在這個執行個體中的位置。
-或-
startIndex 或 length 小於零。
startIndex 是以零起始的。
下列程式碼範例會在三個案例下使用 Substring 方法,以隔離字串內的子字串。在兩個案例下,這些子字串會用於比較作業,而在第三個案例下,會因為指定了無效的參數而擲回例外狀況。
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.
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.
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.
String myString = "abc"; // This is true. boolean test1 = String.Compare(myString.Substring(2, 1), "c") == 0; myString.Substring(3, 1); // This throws ArgumentOutOfRangeException. // This is true. boolean test2 = String.Compare(myString.Substring(3, 0), " ") == 0;
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.
Windows 98、 Windows 2000 SP4、 Windows Millennium Edition、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition
.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。