String.Substring メソッド (Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim startIndex As Integer Dim length As Integer Dim returnValue As String returnValue = instance.Substring(startIndex, length)
戻り値
このインスタンスの startIndex から長さ length を抽出することによって得られる部分文字列と等しい String。または、startIndex がこのインスタンスの長さと等しく、length がゼロの場合は Empty。



Substring メソッドを使用して、文字列から部分文字列を取り出す 3 つのコード例を次に示します。そのうち 2 つは、比較処理に部分文字列を使用しています。3 つ目の例では、無効なパラメータを指定しているため例外がスローされます。
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.

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Substring メソッド (Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim startIndex As Integer Dim returnValue As String returnValue = instance.Substring(startIndex)
戻り値
このインスタンスの startIndex で始まる部分文字列と等しい String オブジェクト。または、startIndex がこのインスタンスの長さと等しい場合は Empty。



Imports System Public Class SubStringTest Public Shared Sub Main() Dim info As String() = {"Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"} Dim found As Integer = 0 Console.WriteLine("The initial values in the array are:") Dim s As String For Each s In info Console.WriteLine(s) Next s Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine) For Each s In info found = s.IndexOf(":") Console.WriteLine(s.Substring((found + 1)).Trim()) Next s End Sub 'Main End Class 'SubStringTest
using System; public class SubStringTest { public static void Main() { string [] info = {"Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"}; int found = 0; Console.WriteLine("The initial values in the array are:"); foreach (string s in info) Console.WriteLine(s); Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine); foreach (string s in info) { found = s.IndexOf(":"); Console.WriteLine(s.Substring(found + 1).Trim()); } } }
using namespace System; using namespace System::Collections; int main() { array<String^>^info = {"Name: Felica Walker","Title: Mz.","Age: 47","Location: Paris","Gender: F"}; int found = 0; Console::WriteLine( "The initial values in the array are:" ); IEnumerator^ myEnum1 = info->GetEnumerator(); while ( myEnum1->MoveNext() ) { String^ s = safe_cast<String^>(myEnum1->Current); Console::WriteLine( s ); } Console::WriteLine( "\nWe want to retrieve only the key information. That is:" ); IEnumerator^ myEnum2 = info->GetEnumerator(); while ( myEnum2->MoveNext() ) { String^ s = safe_cast<String^>(myEnum2->Current); found = s->IndexOf( ":" ); Console::WriteLine( s->Substring( found + 1 )->Trim() ); } }
import System.*; public class SubStringTest { public static void main(String[] args) { String info[] = { "Name: Felica Walker", "Title: Mz." , "Age: 47", "Location: Paris", "Gender: F" }; int found = 0; Console.WriteLine("The initial values in the array are:"); for (int iCtr = 0; iCtr < info.get_Length(); iCtr++) { String s = info[iCtr]; Console.WriteLine(s); } Console.WriteLine("{0}We want to retrieve only the key information." + " That is:", Environment.get_NewLine()); for (int iCtr = 0; iCtr < info.get_Length(); iCtr++) { String s = info[iCtr]; found = s.IndexOf(":"); Console.WriteLine(s.Substring(found + 1).Trim()); } } //main } //SubStringTest
import System; public class SubStringTest { public static function Main() : void { var info : String [] = ["Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"]; var found : int = 0; Console.WriteLine("The initial values in the array are:"); for (var i : int in info) Console.WriteLine(info[i]); Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine); for (i in info) { found = info[i].IndexOf(":"); Console.WriteLine(info[i].Substring(found + 1).Trim()); } } } SubStringTest.Main();

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Substring メソッド
Weblioに収録されているすべての辞書からString.Substringを検索する場合は、下記のリンクをクリックしてください。

- String.Substringのページへのリンク