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

Dim instance As String Dim returnValue As String returnValue = instance.Trim
このインスタンスと等価で、先頭と末尾から空白文字が削除された新しい String。

Trim メソッドで削除可能な空白文字を次の表に示します。1 列目は文字の Unicode 名を、2 列目はその文字に対応する Unicode コード ポイント (16 進表記) を示しています。

Trim(Char[]) メソッド オーバーロードのコード例を次に示します。
Imports System Public Class TrimTest Public Shared Sub Main() Dim temp As String() = MakeArray() Console.WriteLine("Concatenating the inital values in the array, we get the string:") Console.WriteLine("'{0}'{1}", [String].Concat(temp), Environment.NewLine) Dim i As Integer ' trim whitespace from both ends of the elements For i = 0 To temp.Length - 1 temp(i) = temp(i).Trim() Next i Console.WriteLine("Concatenating the trimmed values in the array, we get the string:") Console.WriteLine("'{0}'{1}", [String].Concat(temp), Environment.NewLine) ' reset the array temp = MakeArray() ' trim the start of the elements. Passing null trims whitespace only For i = 0 To temp.Length - 1 temp(i) = temp(i).TrimStart(" "c) Next i Console.WriteLine("Concatenating the start-trimmed values in the array, we get the string:") Console.WriteLine("'{0}'{1}", [String].Concat(temp), Environment.NewLine) ' reset the array temp = MakeArray() ' trim the end of the elements. Passing null trims whitespace only For i = 0 To temp.Length - 1 temp(i) = temp(i).TrimEnd(" "c) Next i Console.WriteLine("Concatenating the end-trimmed values in the array, we get the string:") Console.WriteLine("'{0}'", [String].Concat(temp)) End Sub 'Main Private Shared Function MakeArray() As String() Dim arr As String() = {" please ", " tell ", " me ", " about ", " yourself "} Return arr End Function 'MakeArray End Class 'TrimTest
using System; public class TrimTest { public static void Main() { string [] temp = MakeArray(); Console.WriteLine("Concatenating the inital values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // trim whitespace from both ends of the elements for (int i = 0; i < temp.Length; i++) temp[i] = temp[i].Trim(); Console.WriteLine("Concatenating the trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // reset the array temp = MakeArray(); // trim the start of the elements. Passing null trims whitespace only for (int i = 0; i < temp.Length; i++) temp[i] = temp[i].TrimStart(null); Console.WriteLine("Concatenating the start-trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // reset the array temp = MakeArray(); // trim the end of the elements. Passing null trims whitespace only for (int i = 0; i < temp.Length; i++) temp[i] = temp[i].TrimEnd(null); Console.WriteLine("Concatenating the end-trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'", String.Concat(temp)); } private static string [] MakeArray() { string [] arr = {" please ", " tell ", " me ", " about ", " yourself "}; return arr; } }
using namespace System; array<String^>^ MakeArray() { array<String^>^arr = {" please "," tell "," me "," about "," yourself "}; return arr; } int main() { array<String^>^temp = MakeArray(); Console::WriteLine( "Concatenating the inital values in the array, we get the string:" ); Console::WriteLine( "'{0}'\n", String::Concat( temp ) ); // trim whitespace from both ends of the elements for ( int i = 0; i < temp->Length; i++ ) temp[ i ] = temp[ i ]->Trim(); Console::WriteLine( "Concatenating the trimmed values in the array, we get the string:" ); Console::WriteLine( "'{0}'", String::Concat( temp ) ); // reset the array temp = MakeArray(); // trim the start of the elements-> Passing 0 trims whitespace only for ( int i = 0; i < temp->Length; i++ ) temp[ i ] = temp[ i ]->TrimStart( 0 ); Console::WriteLine( "Concatenating the start-trimmed values in the array, we get the string:" ); Console::WriteLine( "'{0}'\n", String::Concat( temp ) ); // reset the array temp = MakeArray(); // trim the end of the elements-> Passing 0 trims whitespace only for ( int i = 0; i < temp->Length; i++ ) temp[ i ] = temp[ i ]->TrimEnd( 0 ); Console::WriteLine( "Concatenating the end-trimmed values in the array, we get the string:" ); Console::WriteLine( "'{0}'", String::Concat( temp ) ); }
import System.*; public class TrimTest { public static void main(String[] args) { String temp[] = MakeArray(); Console.WriteLine("Concatenating the inital values in the array," + " we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.get_NewLine()); // trim whitespace from both ends of the elements for (int i = 0; i < temp.get_Length(); i++) { temp.set_Item(i, temp[i].Trim()); } Console.WriteLine("Concatenating the trimmed values in the array," + " we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.get_NewLine()); // reset the array temp = MakeArray(); // trim the start of the elements. Passing null trims whitespace only for (int i = 0; i < temp.get_Length(); i++) { temp.set_Item(i, temp[i].TrimStart(null)); } Console.WriteLine("Concatenating the start-trimmed values in the " + "array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.get_NewLine()); // reset the array temp = MakeArray(); // trim the end of the elements. Passing null trims whitespace only for (int i = 0; i < temp.get_Length(); i++) { temp.set_Item(i, temp[i].TrimEnd(null)); } Console.WriteLine("Concatenating the end-trimmed values in the array," + " we get the string:"); Console.WriteLine("'{0}'", String.Concat(temp)); } //main private static String[] MakeArray() { String arr[] = { " please ", " tell ", " me ", " about ", " yourself " }; return arr; } //MakeArray } //TrimTest
import System; public class TrimTest { public static function Main() : void { var temp : String [] = MakeArray(); Console.WriteLine("Concatenating the inital values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // trim whitespace from both ends of the elements for (var i : int = 0; i < temp.Length; i++) temp[i] = temp[i].Trim(); Console.WriteLine("Concatenating the trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // reset the array temp = MakeArray(); var c : char[] = undefined; // trim the start of the elements. Passing null trims whitespace only for (i = 0; i < temp.Length; i++) temp[i] = temp[i].TrimStart(c); Console.WriteLine("Concatenating the start-trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'{1}", String.Concat(temp), Environment.NewLine); // reset the array temp = MakeArray(); // trim the end of the elements. Passing null trims whitespace only for (i = 0; i < temp.Length; i++) temp[i] = temp[i].TrimEnd(c); Console.WriteLine("Concatenating the end-trimmed values in the array, we get the string:"); Console.WriteLine("'{0}'", String.Concat(temp)); } private static function MakeArray() : String [] { var arr : String [] = [" please ", " tell ", " me ", " about ", " yourself "]; return arr; } } TrimTest.Main();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Trim メソッド (Char[])
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim trimChars As Char() Dim returnValue As String returnValue = instance.Trim(trimChars)
戻り値
このインスタンスの先頭と末尾から、出現する trimChars の文字をすべて削除した後の String。trimChars が null 参照 (Visual Basic では Nothing) の場合は、代わりに空白文字が削除されます。


Trim(Char[]) メソッド オーバーロードのコード例を次に示します。
Imports System _ Class stringTrim2 Public Shared Sub Main() Dim str1 As [String] = "*;|@123***456@|;*" Dim delim As [String] = "*;|@" Dim str2 As [String] = str1.Trim(delim.ToCharArray()) Console.WriteLine("Delimiters: {0}", delim) Console.WriteLine("Original string: {0}", str1) Console.WriteLine("Trimmed string: {0}", str2) End Sub 'Main End Class 'stringTrim2
using System; class stringTrim2 { public static void Main() { String str1 = "*;|@123***456@|;*"; String delim = "*;|@"; String str2 = str1.Trim(delim.ToCharArray()); Console.WriteLine("Delimiters: {0}", delim); Console.WriteLine("Original string: {0}", str1); Console.WriteLine("Trimmed string: {0}", str2); } }
using namespace System; int main() { String^ str1 = "*;|@123***456@|;"; String^ delim = "*;|@"; String^ str2 = str1->Trim( delim->ToCharArray() ); Console::WriteLine( "Delimiters: {0}", delim ); Console::WriteLine( "Original string: {0}", str1 ); Console::WriteLine( "Trimmed string: {0}", str2 ); }
import System.*; class StringTrim2 { public static void main(String[] args) { String str1 = "*;|@123***456@|;*"; String delim = "*;|@"; String str2 = str1.Trim(delim.ToCharArray()); Console.WriteLine("Delimiters: {0}", delim); Console.WriteLine("Original string: {0}", str1); Console.WriteLine("Trimmed string: {0}", str2); } //main } //StringTrim2

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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

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