다음을 통해 공유


StringSplitOptions 열거형

정의

반환된 배열에서 빈 부분 문자열을 생략할지 또는 부분 문자열의 공백을 자를지 등 해당하는 Split 메서드 오버로드에 대한 옵션을 지정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class StringSplitOptions
[System.Flags]
public enum StringSplitOptions
[System.Flags]
[System.Runtime.InteropServices.ComVisible(false)]
public enum StringSplitOptions
[<System.Flags>]
type StringSplitOptions = 
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type StringSplitOptions = 
Public Enum StringSplitOptions
상속
StringSplitOptions
특성

필드

None 0

문자열을 분할할 때 기본 옵션을 사용합니다.

RemoveEmptyEntries 1

결과의 빈 문자열을 포함하는 배열 요소를 생략합니다.

RemoveEmptyEntriesTrimEntries가 함께 지정된 경우 공백 문자로만 구성된 substring도 결과에서 제거됩니다.

TrimEntries 2

결과의 각 부분 문자열에서 공백 문자를 자림합니다. 이 필드는 .NET 5 이상 버전에서만 사용할 수 있습니다.

RemoveEmptyEntriesTrimEntries가 함께 지정된 경우 공백 문자로만 구성된 substring도 결과에서 제거됩니다.

예제

다음 예제에서는 열거형을 StringSplitOptions 사용하여 메서드에서 생성된 String.Split 부분 문자열을 포함하거나 제외하는 방법을 보여 줍니다.

// This example demonstrates the String.Split(Char[], Boolean) and 
//                               String.Split(Char[], Int32, Boolean) methods
using namespace System;
void Show( array<String^>^entries )
{
   Console::WriteLine( "The return value contains these {0} elements:", entries->Length );
   System::Collections::IEnumerator^ myEnum = entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ entry = safe_cast<String^>(myEnum->Current);
      Console::Write( "<{0}>", entry );
   }

   Console::Write( "{0}{0}", Environment::NewLine );
}

int main()
{
   String^ s = ",one,,,two,,,,,three,,";
   array<Char>^sep = gcnew array<Char>{
      ','
   };
   array<String^>^result;
   
   //
   Console::WriteLine( "The original string is \"{0}\".", s );
   Console::WriteLine( "The separation character is '{0}'.", sep[ 0 ] );
   Console::WriteLine();
   
   //
   Console::WriteLine( "Split the string and return all elements:" );
   result = s->Split( sep, StringSplitOptions::None );
   Show( result );
   
   //
   Console::WriteLine( "Split the string and return all non-empty elements:" );
   result = s->Split( sep, StringSplitOptions::RemoveEmptyEntries );
   Show( result );
   
   //
   Console::WriteLine( "Split the string and return 2 elements:" );
   result = s->Split( sep, 2, StringSplitOptions::None );
   Show( result );
   
   //
   Console::WriteLine( "Split the string and return 2 non-empty elements:" );
   result = s->Split( sep, 2, StringSplitOptions::RemoveEmptyEntries );
   Show( result );
}

/*
This example produces the following results:

The original string is ",one,,,two,,,,,three,,".
The separation character is ','.

Split the string and return all elements:
The return value contains these 12 elements:
<><one><><><two><><><><><three><><>

Split the string and return all non-empty elements:
The return value contains these 3 elements:
<one><two><three>

Split the string and return 2 elements:
The return value contains these 2 elements:
<><one,,,two,,,,,three,,>

Split the string and return 2 non-empty elements:
The return value contains these 2 elements:
<one><,,two,,,,,three,,>

*/
// This example demonstrates the String.Split() methods that use
// the StringSplitOptions enumeration.

// Example 1: Split a string delimited by characters
Console.WriteLine("1) Split a string delimited by characters:\n");

string s1 = ",ONE,, TWO,, , THREE,,";
char[] charSeparators = new char[] { ',' };
string[] result;

Console.WriteLine($"The original string is: \"{s1}\".");
Console.WriteLine($"The delimiter character is: '{charSeparators[0]}'.\n");

// Split the string and return all elements
Console.WriteLine("1a) Return all elements:");
result = s1.Split(charSeparators, StringSplitOptions.None);
Show(result);

// Split the string and return all elements with whitespace trimmed
Console.WriteLine("1b) Return all elements with whitespace trimmed:");
result = s1.Split(charSeparators, StringSplitOptions.TrimEntries);
Show(result);

// Split the string and return all non-empty elements
Console.WriteLine("1c) Return all non-empty elements:");
result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the string and return all non-whitespace elements with whitespace trimmed
Console.WriteLine("1d) Return all non-whitespace elements with whitespace trimmed:");
result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Show(result);


// Split the string into only two elements, keeping the remainder in the last match
Console.WriteLine("1e) Split into only two elements:");
result = s1.Split(charSeparators, 2, StringSplitOptions.None);
Show(result);

// Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
Console.WriteLine("1f) Split into only two elements with whitespace trimmed:");
result = s1.Split(charSeparators, 2, StringSplitOptions.TrimEntries);
Show(result);

// Split the string into only two non-empty elements, keeping the remainder in the last match
Console.WriteLine("1g) Split into only two non-empty elements:");
result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
Console.WriteLine("1h) Split into only two non-whitespace elements with whitespace trimmed:");
result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Show(result);


// Example 2: Split a string delimited by another string
Console.WriteLine("2) Split a string delimited by another string:\n");

string s2 = "[stop]" +
            "ONE[stop] [stop]" +
            "TWO  [stop][stop]  [stop]" +
            "THREE[stop][stop]  ";
string[] stringSeparators = new string[] { "[stop]" };

Console.WriteLine($"The original string is: \"{s2}\".");
Console.WriteLine($"The delimiter string is: \"{stringSeparators[0]}\".\n");

// Split the string and return all elements
Console.WriteLine("2a) Return all elements:");
result = s2.Split(stringSeparators, StringSplitOptions.None);
Show(result);

// Split the string and return all elements with whitespace trimmed
Console.WriteLine("2b) Return all elements with whitespace trimmed:");
result = s2.Split(stringSeparators, StringSplitOptions.TrimEntries);
Show(result);

// Split the string and return all non-empty elements
Console.WriteLine("2c) Return all non-empty elements:");
result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the string and return all non-whitespace elements with whitespace trimmed
Console.WriteLine("2d) Return all non-whitespace elements with whitespace trimmed:");
result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Show(result);


// Split the string into only two elements, keeping the remainder in the last match
Console.WriteLine("2e) Split into only two elements:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.None);
Show(result);

// Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
Console.WriteLine("2f) Split into only two elements with whitespace trimmed:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.TrimEntries);
Show(result);

// Split the string into only two non-empty elements, keeping the remainder in the last match
Console.WriteLine("2g) Split into only two non-empty elements:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
Console.WriteLine("2h) Split into only two non-whitespace elements with whitespace trimmed:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Show(result);


// Display the array of separated strings using a local function
void Show(string[] entries)
{
    Console.WriteLine($"The return value contains these {entries.Length} elements:");
    foreach (string entry in entries)
    {
        Console.Write($"<{entry}>");
    }
    Console.Write("\n\n");
}

/*
This example produces the following results:

1) Split a string delimited by characters:

The original string is: ",ONE,, TWO,, , THREE,,".
The delimiter character is: ','.

1a) Return all elements:
The return value contains these 9 elements:
<><ONE><>< TWO><>< >< THREE><><>

1b) Return all elements with whitespace trimmed:
The return value contains these 9 elements:
<><ONE><><TWO><><><THREE><><>

1c) Return all non-empty elements:
The return value contains these 4 elements:
<ONE>< TWO>< >< THREE>

1d) Return all non-whitespace elements with whitespace trimmed:
The return value contains these 3 elements:
<ONE><TWO><THREE>

1e) Split into only two elements:
The return value contains these 2 elements:
<><ONE,, TWO,, , THREE,,>

1f) Split into only two elements with whitespace trimmed:
The return value contains these 2 elements:
<><ONE,, TWO,, , THREE,,>

1g) Split into only two non-empty elements:
The return value contains these 2 elements:
<ONE>< TWO,, , THREE,,>

1h) Split into only two non-whitespace elements with whitespace trimmed:
The return value contains these 2 elements:
<ONE><TWO,, , THREE,,>

2) Split a string delimited by another string:

The original string is: "[stop]ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  ".
The delimiter string is: "[stop]".

2a) Return all elements:
The return value contains these 9 elements:
<><ONE>< ><TWO  ><><  ><THREE><><  >

2b) Return all elements with whitespace trimmed:
The return value contains these 9 elements:
<><ONE><><TWO><><><THREE><><>

2c) Return all non-empty elements:
The return value contains these 6 elements:
<ONE>< ><TWO  ><  ><THREE><  >

2d) Return all non-whitespace elements with whitespace trimmed:
The return value contains these 3 elements:
<ONE><TWO><THREE>

2e) Split into only two elements:
The return value contains these 2 elements:
<><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >

2f) Split into only two elements with whitespace trimmed:
The return value contains these 2 elements:
<><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]>

2g) Split into only two non-empty elements:
The return value contains these 2 elements:
<ONE>< [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >

2h) Split into only two non-whitespace elements with whitespace trimmed:
The return value contains these 2 elements:
<ONE><TWO  [stop][stop]  [stop]THREE[stop][stop]>

*/
// This example demonstrates the String.Split() methods that use
// the StringSplitOptions enumeration.

// Display the array of separated strings using a local function
let show  (entries: string[]) =
    printfn $"The return value contains these {entries.Length} elements:"
    for entry in entries do
        printf $"<{entry}>"
    printf "\n\n"

// Example 1: Split a string delimited by characters
printfn "1) Split a string delimited by characters:\n"

let s1 = ",ONE,, TWO,, , THREE,,"
let charSeparators = [| ',' |]

printfn $"The original string is: \"{s1}\"."
printfn $"The delimiter character is: '{charSeparators[0]}'.\n"

// Split the string and return all elements
printfn "1a) Return all elements:"
let result = s1.Split(charSeparators, StringSplitOptions.None)
show result

// Split the string and return all elements with whitespace trimmed
printfn "1b) Return all elements with whitespace trimmed:"
let result = s1.Split(charSeparators, StringSplitOptions.TrimEntries)
show result

// Split the string and return all non-empty elements
printfn "1c) Return all non-empty elements:"
let result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries)
show result

// Split the string and return all non-whitespace elements with whitespace trimmed
printfn "1d) Return all non-whitespace elements with whitespace trimmed:"
let result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
show result


// Split the string into only two elements, keeping the remainder in the last match
printfn "1e) Split into only two elements:"
let result = s1.Split(charSeparators, 2, StringSplitOptions.None)
show result

// Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
printfn "1f) Split into only two elements with whitespace trimmed:"
let result = s1.Split(charSeparators, 2, StringSplitOptions.TrimEntries)
show result

// Split the string into only two non-empty elements, keeping the remainder in the last match
printfn "1g) Split into only two non-empty elements:"
let result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
show result

// Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
printfn "1h) Split into only two non-whitespace elements with whitespace trimmed:"
let result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
show result


// Example 2: Split a string delimited by another string
printfn "2) Split a string delimited by another string:\n"

let s2 = "[stop]" +
            "ONE[stop] [stop]" +
            "TWO  [stop][stop]  [stop]" +
            "THREE[stop][stop]  "
let stringSeparators = [| "[stop]" |]

printfn $"The original string is: \"{s2}\"."
printfn $"The delimiter string is: \"{stringSeparators[0]}\".\n"

// Split the string and return all elements
printfn "2a) Return all elements:"
let result = s2.Split(stringSeparators, StringSplitOptions.None)
show result

// Split the string and return all elements with whitespace trimmed
printfn "2b) Return all elements with whitespace trimmed:"
let result = s2.Split(stringSeparators, StringSplitOptions.TrimEntries)
show result

// Split the string and return all non-empty elements
printfn "2c) Return all non-empty elements:"
let result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries)
show result

// Split the string and return all non-whitespace elements with whitespace trimmed
printfn "2d) Return all non-whitespace elements with whitespace trimmed:"
let result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
show result


// Split the string into only two elements, keeping the remainder in the last match
printfn "2e) Split into only two elements:"
let result = s2.Split(stringSeparators, 2, StringSplitOptions.None)
show result

// Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
printfn "2f) Split into only two elements with whitespace trimmed:"
let result = s2.Split(stringSeparators, 2, StringSplitOptions.TrimEntries)
show result

// Split the string into only two non-empty elements, keeping the remainder in the last match
printfn "2g) Split into only two non-empty elements:"
let result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
show result

// Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
printfn "2h) Split into only two non-whitespace elements with whitespace trimmed:"
let result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
show result

(*
This example produces the following results:

1) Split a string delimited by characters:

The original string is: ",ONE,, TWO,, , THREE,,".
The delimiter character is: ','.

1a) Return all elements:
The return value contains these 9 elements:
<><ONE><>< TWO><>< >< THREE><><>

1b) Return all elements with whitespace trimmed:
The return value contains these 9 elements:
<><ONE><><TWO><><><THREE><><>

1c) Return all non-empty elements:
The return value contains these 4 elements:
<ONE>< TWO>< >< THREE>

1d) Return all non-whitespace elements with whitespace trimmed:
The return value contains these 3 elements:
<ONE><TWO><THREE>

1e) Split into only two elements:
The return value contains these 2 elements:
<><ONE,, TWO,, , THREE,,>

1f) Split into only two elements with whitespace trimmed:
The return value contains these 2 elements:
<><ONE,, TWO,, , THREE,,>

1g) Split into only two non-empty elements:
The return value contains these 2 elements:
<ONE>< TWO,, , THREE,,>

1h) Split into only two non-whitespace elements with whitespace trimmed:
The return value contains these 2 elements:
<ONE><TWO,, , THREE,,>

2) Split a string delimited by another string:

The original string is: "[stop]ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  ".
The delimiter string is: "[stop]".

2a) Return all elements:
The return value contains these 9 elements:
<><ONE>< ><TWO  ><><  ><THREE><><  >

2b) Return all elements with whitespace trimmed:
The return value contains these 9 elements:
<><ONE><><TWO><><><THREE><><>

2c) Return all non-empty elements:
The return value contains these 6 elements:
<ONE>< ><TWO  ><  ><THREE><  >

2d) Return all non-whitespace elements with whitespace trimmed:
The return value contains these 3 elements:
<ONE><TWO><THREE>

2e) Split into only two elements:
The return value contains these 2 elements:
<><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >

2f) Split into only two elements with whitespace trimmed:
The return value contains these 2 elements:
<><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]>

2g) Split into only two non-empty elements:
The return value contains these 2 elements:
<ONE>< [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >

2h) Split into only two non-whitespace elements with whitespace trimmed:
The return value contains these 2 elements:
<ONE><TWO  [stop][stop]  [stop]THREE[stop][stop]>

*)
Public Shared Sub StringSplitOptionsExamples()
    ' This example demonstrates the String.Split() methods that use
    ' the StringSplitOptions enumeration.

    ' Example 1: Split a string delimited by characters
    Console.WriteLine("1) Split a string delimited by characters:" & vbCrLf)

    Dim s1 As String = ",ONE,, TWO,, , THREE,,"
    Dim charSeparators() As Char = {","c}
    Dim result() As String

    Console.WriteLine("The original string is: ""{0}"".", s1)
    Console.WriteLine("The delimiter character is: '{0}'." & vbCrLf, charSeparators(0))

    ' Split the string and return all elements
    Console.WriteLine("1a) Return all elements:")
    result = s1.Split(charSeparators, StringSplitOptions.None)
    Show(result)

    ' Split the string and return all elements with whitespace trimmed
    Console.WriteLine("1b) Return all elements with whitespace trimmed:")
    result = s1.Split(charSeparators, StringSplitOptions.TrimEntries)
    Show(result)

    ' Split the string and return all non-empty elements
    Console.WriteLine("1c) Return all non-empty elements:")
    result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries)
    Show(result)

    ' Split the string and return all non-whitespace elements with whitespace trimmed
    Console.WriteLine("1d) Return all non-whitespace elements with whitespace trimmed:")
    result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries Or StringSplitOptions.TrimEntries)
    Show(result)


    ' Split the string into only two elements, keeping the remainder in the last match
    Console.WriteLine("1e) Split into only two elements:")
    result = s1.Split(charSeparators, 2, StringSplitOptions.None)
    Show(result)

    ' Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
    Console.WriteLine("1f) Split into only two elements with whitespace trimmed:")
    result = s1.Split(charSeparators, 2, StringSplitOptions.TrimEntries)
    Show(result)

    ' Split the string into only two non-empty elements, keeping the remainder in the last match
    Console.WriteLine("1g) Split into only two non-empty elements:")
    result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
    Show(result)

    ' Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
    Console.WriteLine("1h) Split into only two non-whitespace elements with whitespace trimmed:")
    result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries Or StringSplitOptions.TrimEntries)
    Show(result)


    ' Example 2: Split a string delimited by another string
    Console.WriteLine("2) Split a string delimited by another string:" & vbCrLf)

    Dim s2 As String = "[stop]" +
                "ONE[stop] [stop]" +
                "TWO  [stop][stop]  [stop]" +
                "THREE[stop][stop]  "
    Dim stringSeparators() As String = {"[stop]"}


    Console.WriteLine("The original string is: ""{0}"".", s2)
    Console.WriteLine("The delimiter string is: ""{0}""." & vbCrLf, stringSeparators(0))

    ' Split the string and return all elements
    Console.WriteLine("2a) Return all elements:")
    result = s2.Split(stringSeparators, StringSplitOptions.None)
    Show(result)

    ' Split the string and return all elements with whitespace trimmed
    Console.WriteLine("2b) Return all elements with whitespace trimmed:")
    result = s2.Split(stringSeparators, StringSplitOptions.TrimEntries)
    Show(result)

    ' Split the string and return all non-empty elements
    Console.WriteLine("2c) Return all non-empty elements:")
    result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries)
    Show(result)

    ' Split the string and return all non-whitespace elements with whitespace trimmed
    Console.WriteLine("2d) Return all non-whitespace elements with whitespace trimmed:")
    result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries Or StringSplitOptions.TrimEntries)
    Show(result)


    ' Split the string into only two elements, keeping the remainder in the last match
    Console.WriteLine("2e) Split into only two elements:")
    result = s2.Split(stringSeparators, 2, StringSplitOptions.None)
    Show(result)

    ' Split the string into only two elements with whitespace trimmed, keeping the remainder in the last match
    Console.WriteLine("2f) Split into only two elements with whitespace trimmed:")
    result = s2.Split(stringSeparators, 2, StringSplitOptions.TrimEntries)
    Show(result)

    ' Split the string into only two non-empty elements, keeping the remainder in the last match
    Console.WriteLine("2g) Split into only two non-empty elements:")
    result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
    Show(result)

    ' Split the string into only two non-whitespace elements with whitespace trimmed, keeping the remainder in the last match
    Console.WriteLine("2h) Split into only two non-whitespace elements with whitespace trimmed:")
    result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries Or StringSplitOptions.TrimEntries)
    Show(result)

End Sub

' Display the array of separated strings.
Public Shared Sub Show(ByVal entries() As String)
    Console.WriteLine("The return value contains these {0} elements:", entries.Length)
    Dim entry As String
    For Each entry In entries
        Console.Write("<{0}>", entry)
    Next entry
    Console.Write(vbCrLf & vbCrLf)

End Sub

'This example produces the following results:
'
' 1) Split a string delimited by characters:
'
' The original string is: ",ONE,, TWO,, , THREE,,".
' The delimiter character is: ','.
'
' 1a) Return all elements:
' The return value contains these 9 elements:
' <><ONE><>< TWO><>< >< THREE><><>
'
' 1b) Return all elements with whitespace trimmed:
' The return value contains these 9 elements:
' <><ONE><><TWO><><><THREE><><>
'
' 1c) Return all non-empty elements:
' The return value contains these 4 elements:
' <ONE>< TWO>< >< THREE>
'
' 1d) Return all non-whitespace elements with whitespace trimmed:
' The return value contains these 3 elements:
' <ONE><TWO><THREE>
'
' 1e) Split into only two elements:
' The return value contains these 2 elements:
' <><ONE,, TWO,, , THREE,,>
'
' 1f) Split into only two elements with whitespace trimmed:
' The return value contains these 2 elements:
' <><ONE,, TWO,, , THREE,,>
'
' 1g) Split into only two non-empty elements:
' The return value contains these 2 elements:
' <ONE>< TWO,, , THREE,,>
'
' 1h) Split into only two non-whitespace elements with whitespace trimmed:
' The return value contains these 2 elements:
' <ONE><TWO,, , THREE,,>
'
' 2) Split a string delimited by another string:
'
' The original string is: "[stop]ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  ".
' The delimiter string is: "[stop]".
'
' 2a) Return all elements:
' The return value contains these 9 elements:
' <><ONE>< ><TWO  ><><  ><THREE><><  >
'
' 2b) Return all elements with whitespace trimmed:
' The return value contains these 9 elements:
' <><ONE><><TWO><><><THREE><><>
'
' 2c) Return all non-empty elements:
' The return value contains these 6 elements:
' <ONE>< ><TWO  ><  ><THREE><  >
'
' 2d) Return all non-whitespace elements with whitespace trimmed:
' The return value contains these 3 elements:
' <ONE><TWO><THREE>
'
' 2e) Split into only two elements:
' The return value contains these 2 elements:
' <><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >
'
' 2f) Split into only two elements with whitespace trimmed:
' The return value contains these 2 elements:
' <><ONE[stop] [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]>
'
' 2g) Split into only two non-empty elements:
' The return value contains these 2 elements:
' <ONE>< [stop]TWO  [stop][stop]  [stop]THREE[stop][stop]  >
'
' 2h) Split into only two non-whitespace elements with whitespace trimmed:
' The return value contains these 2 elements:
' <ONE><TWO  [stop][stop]  [stop]THREE[stop][stop]>
'

설명

메서드는 String.Split 지정된 문자 또는 문자열로 구분된 지정된 문자열의 부분 문자열 배열을 반환합니다. 인접한 구분 기호는 빈 문자열("")을 포함하는 배열 요소를 생성합니다. 열거형의 StringSplitOptions 필드 중 하나는 빈 문자열을 포함하는 요소를 반환된 배열에 포함할지 여부를 지정합니다.

None 공백 문자를 트리밍하지 않고 빈 부분 문자열을 포함하는 메서드의 String.Split 기본 동작을 호출할 필드를 지정합니다.

TrimEntries 필드는 .NET 5 이상 버전에서만 사용할 수 있습니다.

적용 대상

추가 정보