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

Dim instance As String Dim startIndex As Integer Dim returnValue As String returnValue = instance.Remove(startIndex)
戻り値
この文字列から対象となる文字を取り除いた新しい String オブジェクト。


Remove メソッドのコード例を次に示します。2 番目の例では、指定したインデックス位置から文字列の終端までのテキストをすべて削除しています。3 番目の例では、指定したインデックス位置から 3 文字を削除しています。
' This example demonstrates the String.Remove() method. Imports System Class Sample Public Shared Sub Main() Dim s As String = "abc---def" ' Console.WriteLine("Index: 012345678") Console.WriteLine("1) {0}", s) Console.WriteLine("2) {0}", s.Remove(3)) Console.WriteLine("3) {0}", s.Remove(3, 3)) End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' 'Index: 012345678 '1) abc---def '2) abc '3) abcdef '
// This example demonstrates the String.Remove() method. using System; class Sample { public static void Main() { string s = "abc---def"; // Console.WriteLine("Index: 012345678"); Console.WriteLine("1) {0}", s); Console.WriteLine("2) {0}", s.Remove(3)); Console.WriteLine("3) {0}", s.Remove(3, 3)); } } /* This example produces the following results: Index: 012345678 1) abc---def 2) abc 3) abcdef */
// This example demonstrates the String.Remove() method. using namespace System; int main() { String^ s = "abc---def"; // Console::WriteLine( "Index: 012345678" ); Console::WriteLine( "1) {0}", s ); Console::WriteLine( "2) {0}", s->Remove( 3 ) ); Console::WriteLine( "3) {0}", s->Remove( 3, 3 ) ); } /* This example produces the following results: Index: 012345678 1) abc---def 2) abc 3) abcdef */
// This example demonstrates the String.Remove() method. import System.*; class Sample { public static void main(String[] args) { String s = "abc---def"; // Console.WriteLine("Index: 012345678"); Console.WriteLine("1) {0}", s); Console.WriteLine("2) {0}", s.Remove(3)); Console.WriteLine("3) {0}", s.Remove(3, 3)); } //main } //Sample /* This example produces the following results: Index: 012345678 1) abc---def 2) abc 3) abcdef */

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.Remove メソッド (Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim startIndex As Integer Dim count As Integer Dim returnValue As String returnValue = instance.Remove(startIndex, count)
戻り値
このインスタンスと等価であり、count の数の文字が削除されている新しい String。



氏名 (名、ミドル ネーム、姓) からミドル ネームを削除する方法については、次のコード例を参照してください。
Imports System Public Class RemoveTest Public Shared Sub Main() Dim name As String = "Michelle Violet Banks" Console.WriteLine("The entire name is '{0}'", name) Dim foundS1 As Integer = name.IndexOf(" ") Dim foundS2 As Integer = name.IndexOf(" ", foundS1 + 1) If foundS1 <> foundS2 And foundS1 >= 0 Then ' remove the middle name, identified by finding the spaces in the middle of the name... name = name.Remove(foundS1 + 1, foundS2 - foundS1) Console.WriteLine("After removing the middle name, we are left with '{0}'", name) End If End Sub 'Main End Class 'RemoveTest
using System; public class RemoveTest { public static void Main() { string name = "Michelle Violet Banks"; Console.WriteLine("The entire name is '{0}'", name); // remove the middle name, identified by finding the spaces in the middle of the name... int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); if (foundS1 != foundS2 && foundS1 >= 0) { name = name.Remove(foundS1 + 1, foundS2 - foundS1); Console.WriteLine("After removing the middle name, we are left with '{0}'", name); } } }
using namespace System; int main() { String^ name = "Michelle Violet Banks"; Console::WriteLine( "The entire name is '{0}'", name ); // remove the middle name, identified by finding the spaces in the middle of the name->->. int foundS1 = name->IndexOf( " " ); int foundS2 = name->IndexOf( " ", foundS1 + 1 ); if ( foundS1 != foundS2 && foundS1 >= 0 ) { name = name->Remove( foundS1 + 1, foundS2 - foundS1 ); Console::WriteLine( "After removing the middle name, we are left with '{0}'", name ); } }
import System.*; public class RemoveTest { public static void main(String[] args) { String name = "Michelle Violet Banks"; Console.WriteLine("The entire name is '{0}'", name); // remove the middle name, identified by finding the spaces in // the middle of the name... int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); if (foundS1 != foundS2 && foundS1 >= 0) { name = name.Remove(foundS1 + 1, foundS2 - foundS1); Console.WriteLine("After removing the middle name, we are left with" + " '{0}'", name); } } //main } //RemoveTest
import System; public class RemoveTest { public static function Main() : void { var name : String = "Michelle Violet Banks"; Console.WriteLine("The entire name is '{0}'", name); // remove the middle name, identified by finding the spaces in the middle of the name... var foundS1 : int = name.IndexOf(" "); var foundS2 : int = name.IndexOf(" ", foundS1 + 1); if (foundS1 != foundS2 && foundS1 >= 0) { name = name.Remove(foundS1 + 1, foundS2 - foundS1); Console.WriteLine("After removing the middle name, we are left with '{0}'", name); } } } RemoveTest.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.Remove メソッド
- String.Removeのページへのリンク