String.TrimStart メソッドとは? わかりやすく解説

String.TrimStart メソッド

このインスタンス先頭から、配列指定され文字セットをすべて削除します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function TrimStart ( _
    ParamArray trimChars As Char()
 _
) As String
Dim instance As String
Dim trimChars As Char()
Dim returnValue As String

returnValue = instance.TrimStart(trimChars)
public string TrimStart (
    params char[] trimChars
)
public:
String^ TrimStart (
    ... array<wchar_t>^ trimChars
)
public String TrimStart (
    char[] trimChars
)
public function TrimStart (
    ... trimChars : char[]
) : String

パラメータ

trimChars

削除する Unicode 文字配列、または null 参照 (Visual Basic では Nothing)。

戻り値
出現する trimChars文字先頭からすべて削除した後の StringtrimCharsnull 参照 (Visual Basic では Nothing) の場合は、代わりに空白文字削除されます。

解説解説
使用例使用例

TrimStart メソッド オーバーロード使用して文字列先頭から空白その他の文字削除する方法については、次のコード例参照してください

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();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からString.TrimStart メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からString.TrimStart メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からString.TrimStart メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

String.TrimStart メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.TrimStart メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS