Strings.Split(String, String, Int32, CompareMethod) 메서드
정의
지정된 수의 부분 문자열을 포함하는 0부터 시작하는 1차원 배열을 반환합니다.Returns a zero-based, one-dimensional array containing a specified number of substrings.
public static string[]? Split (string Expression, string Delimiter = " ", int Limit = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static string[] Split (string Expression, string Delimiter = " ", int Limit = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member Split : string * string * int * Microsoft.VisualBasic.CompareMethod -> string[]
Public Function Split (Expression As String, Optional Delimiter As String = " ", Optional Limit As Integer = -1, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As String()
매개 변수
- Expression
- String
필수 요소.Required. 부분 문자열과 구분 기호를 포함하는 String
식입니다.String
expression containing substrings and delimiters.
- Delimiter
- String
선택 사항입니다.Optional. 부분 문자열의 한계를 식별하기 위해 사용되는 단일 문자입니다.Any single character used to identify substring limits. Delimiter
를 생략하면 공백 문자(" ")가 구분 기호로 간주됩니다.If Delimiter
is omitted, the space character (" ") is assumed to be the delimiter.
- Limit
- Int32
선택 사항입니다.Optional. 입력 문자열을 분할해야 하는 부분 문자열의 최대 수입니다.Maximum number of substrings into which the input string should be split. 기본값 -1은 Delimiter
문자열이 발생할 때마다 입력 문자열을 분할해야 함을 나타냅니다.The default, -1, indicates that the input string should be split at every occurrence of the Delimiter
string.
- Compare
- CompareMethod
선택 사항입니다.Optional. 부분 문자열을 평가할 때 사용할 비교 종류를 나타내는 숫자 값입니다.Numeric value indicating the comparison to use when evaluating substrings. 값에 대해서는 "설정"을 참조하세요.See "Settings" for values.
반환
- String[]
String
배열입니다.String
array. Expression
이 길이가 0인 문자열("")인 경우 Split
는 길이가 0인 문자열이 포함된 단일 요소 배열을 반환합니다.If Expression
is a zero-length string (""), Split
returns a single-element array containing a zero-length string. Delimiter
가 길이가 0인 문자열이거나 Expression
의 어떤 위치에도 표시되지 않을 경우 Split
는 전체 Expression
문자열이 포함된 단일 요소 배열을 반환합니다.If Delimiter
is a zero-length string, or if it does not appear anywhere in Expression
, Split
returns a single-element array containing the entire Expression
string.
예제
다음 예제에서는 문자열을 해당 공간에 분할 하는 방법을 보여 줍니다.The following example demonstrates how to split a string at its spaces.
Dim testString As String = "Look at these!"
' Returns an array containing "Look", "at", and "these!".
Dim testArray() As String = Split(testString)
다음 예에서는 여러 구분 기호를 포함 하는 문자열을 행으로 분할 하 고 빈 문자열을 필터링 하는 방법을 보여 줍니다.The following example demonstrates how to split strings with multiple delimiters in a row and filter out the empty strings.
Dim testString As String = "apple pear banana "
Dim testArray() As String = Split(testString)
' testArray holds {"apple", "", "", "", "pear", "banana", "", ""}
Dim lastNonEmpty As Integer = -1
For i As Integer = 0 To testArray.Length - 1
If testArray(i) <> "" Then
lastNonEmpty += 1
testArray(lastNonEmpty) = testArray(i)
End If
Next
ReDim Preserve testArray(lastNonEmpty)
' testArray now holds {"apple", "pear", "banana"}
설명
기본적으로 또는 Limit
가-1과 같은 경우 Split
함수는 구분 기호 문자열의 모든 항목에서 입력 문자열을 분할 하 고 배열에서 부분 문자열을 반환 합니다.By default, or when Limit
equals -1, the Split
function splits the input string at every occurrence of the delimiter string, and returns the substrings in an array. Limit
매개 변수가 0 보다 큰 경우 Split
함수는 구분 기호의 처음 1 개에서 문자열을 분할 Limit
하 고 결과 부분 문자열이 포함 된 배열을 반환 합니다.When the Limit
parameter is greater than zero, the Split
function splits the string at the first Limit
-1 occurrences of the delimiter, and returns an array with the resulting substrings. 예를 들어 Split("a:b:c", ":")
는 배열을 반환 {"a", "b", "c"}
하는 반면는 배열을 반환 합니다 Split("a:b:c", ":", 2)
{"a", "b:c"}
.For example, Split("a:b:c", ":")
returns the array {"a", "b", "c"}
, while Split("a:b:c", ":", 2)
returns the array {"a", "b:c"}
.
Split
함수가 행에 두 개의 구분 기호를 발견 하거나 문자열의 시작 또는 끝에 구분 기호를 발견 하면 빈 문자열 ("")을 둘러싼 것으로 해석 됩니다.When the Split
function encounters two delimiters in a row, or a delimiter at the beginning or end of the string, it interprets them as surrounding an empty string (""). 예를 Split("xx", "x")
들어는 세 개의 빈 문자열이 포함 된 배열을 반환 합니다. 하나는 문자열의 시작 부분과 첫 번째 "x" 사이에 있고, 두 개의 "x" 문자열 사이에서 1을 반환 하 고, 마지막 "x"와 문자열의 끝 사이에 있는 문자열을 반환 합니다.For example, Split("xx", "x")
returns the array containing three empty strings: one from between the beginning of the string and the first "x", one from between the two "x" strings, and one from between the last "x" and the end of the string.
이 표에서는 선택적 Delimiter
, Limit
및 Compare
매개 변수가 함수의 동작을 변경할 수 있는 방법을 보여 줍니다 Split
.This table demonstrates how the optional Delimiter
, Limit
, and Compare
parameters can change the behavior of the Split
function.
호출 분할Split Call | 반환 값Return Value |
---|---|
Split("42, 12, 19") |
{"42,", "12", "19"}{"42," , "12," , "19"} |
Split("42, 12, 19", ", ") |
{"42", "12", "19"}{"42", "12", "19"} |
Split("42, 12, 19", ", ", 2) |
{"42", "12, 19"}{"42", "12, 19"} |
Split("192.168.0.1", ".") |
{"192", "168", "0", "1"}{"192", "168", "0", "1"} |
Split("Alice and Bob", " AND ") |
{"Alice 및 Bob"}{"Alice and Bob"} |
Split("Alice and Bob", " AND ", ,CompareMethod.Text) |
{"Alice", "Bob"}{"Alice", "Bob"} |
Split("someone@example.com", "@",1) |
{"someone@example.com"}{"someone@example.com"} |
Split("someone@example.com", "@",2) |
{"사람", "example.com"}{"someone", "example.com"} |
인수에는 Compare
다음 값을 사용할 수 있습니다.The Compare
argument can have the following values.
상수Constant | 설명Description | 값Value |
---|---|---|
CompareMethod.Binary |
이진 비교를 수행 합니다.Performs a binary comparison | 00 |
CompareMethod.Text |
텍스트 비교를 수행 합니다.Performs a textual comparison | 11 |