다음을 통해 공유


String.TrimEnd 메서드

배열에 지정된 문자를 이 인스턴스의 끝에서 모두 제거합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Function TrimEnd ( _
    ParamArray trimChars As Char() _
) As String
‘사용 방법
Dim instance As String
Dim trimChars As Char()
Dim returnValue As String

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

매개 변수

  • trimChars
    Null 참조(Visual Basic의 경우 Nothing)이거나 제거될 유니코드 문자 배열입니다.

반환 값

trimChars에 포함된 모든 문자가 끝에서 제거된 후 남아 있는 String을 반환합니다. trimChars가 Null 참조(Visual Basic의 경우 Nothing)이면, 공백 문자가 대신 제거됩니다.

설명

공백 문자로 분류되는 유니코드 문자에 대한 자세한 내용은 Trim 메서드 오버로드의 설명 부분을 참조하십시오.

예제

다음 코드 예제에서는 TrimEnd 메서드 오버로드를 사용하여 문자열 끝에서 공백이나 다른 문자를 트리밍하는 방법을 보여 줍니다.

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

String 클래스
String 멤버
System 네임스페이스
Char 구조체
Trim
TrimStart