StrSplit() [v1.1.13+]

문자열을 지정된 가름자를 사용하여 부분 문자열 배열로 가릅니다.

Array := StrSplit(String , Delimiters, OmitChars, MaxParts)

매개변수

String

분리할 문자열.

Delimiters

이 매개변수가 비어 있거나 생략되면, 입력 문자열의 각 문자는 별도의 부문자열로 간주됩니다.

그렇지 않으면, Delimiters는 단일 문자열이거나 문자열 배열일 수 있습니다. 각 구분자는 부문자열 사이의 경계가 나타나는 곳을 결정하는데 사용됩니다. 구분자는 부문자열의 일부분으로 간주되지 않으므로, 절대로 반환된 배열에 포함되지 않습니다. 또한, 입력 문자열에서 구분자 한 쌍 사이에 아무것도 없다면, 그에 상응하는 배열 원소는 빈 원소입니다.

예를 들어: ","는 문자열을 쉼표가 나타날 때마다 분리합니다. 비슷하게, [A_Tab, A_Space]는 입력 문자열에서 스페이스나 탭을 만날 때마다 새 배열 원소를 생성합니다.

OmitChars

각 배열 원소의 앞과 뒤로부터 배제할 문자열의 리스트 (대소문자 구분, 선택적). For example, if OmitChars is " `t", spaces and tabs will be removed from the beginning and end (but not the middle) of every element.

Delimiters가 비어 있으면, OmitChars는 배열로부터 어느 문자를 배제해야 하는지를 나타냅니다.

MaxParts [v1.1.28+]
If omitted, it defaults to -1, which means "no limit". Otherwise, specify the maximum number of substrings to return. If non-zero, the string is split a maximum of MaxParts-1 times and the remainder of the string is returned in the last substring (excluding any leading or trailing OmitChars).

반환 값

This function returns an array (object) of strings.

논평

스페이스와 탭 같은 공백 문자들은 유지됩니다. 단, 그 문자 자체가 구분자이거나 OmitChars에 포함되는 경우는 예외입니다. 탭과 스페이스는 Trim 함수를 호출해 변수의 양쪽 끝으로부터 다듬을 수 있습니다. 예를 들어: MyArray1 := Trim(MyArray1).

표준 CSV (쉼표로 가른 값(comma separated value)) 형식의 문자열을 가르려면, 파싱 회돌이를 사용하십시오. CSV 처리가 내장되어 있습니다.

문자열을 가르기 전에 필드를 다른 순서로 정렬하려면, Sort 명령어를 사용하십시오.

부문자열을 메모리에 영원히 저장할 필요가 없다면, 파싱 회돌이의 사용을 고려해 보십시오 -- 특히 String가 매우 방대하다면 꼭 고려해 보시기를 바랍니다. 그런 경우는 방대한 양의 메모리가 저장될 것입니다. 예를 들어:

Colors := "red,green,blue"
Loop, Parse, Colors, % ","
    MsgBox % "Color number " A_Index " is " A_LoopField

StringSplit, Parsing loop, Arrays, Sort, SplitPath, InStr(), SubStr(), StrLen(), StringLower, StringUpper, StrReplace()

예제

Separates a sentence into an array of words and reports the fourth word.

TestString := "This is a test."
word_array := StrSplit(TestString, A_Space, ".") ; 점은 제외합니다.
MsgBox % "The 4th word is " word_array[4]

Separates a comma-separated list of colors into an array of substrings and traverses them, one by one.

colors := "red,green,blue"
for index, color in StrSplit(colors, ",")
    MsgBox % "Color number " index " is " color