SubStr() [v1.0.46+]

문자열에서 지정된 위치로부터 하나 이상이 문자를 열람합니다.

NewStr := SubStr(String, StartingPos , Length)

매개변수

String

The string whose content is copied.

StartingPos

1을 지정하면 첫 번째 문자에서, 2을 지정하면 2번째 문자부터 시작합니다. 등등. ( StartingPosString의 길이를 넘어서면, 빈 문자열이 반환됩니다). StartingPos가 1보다 작으면, 문자열 끝으로부터의 오프셋으로 간주됩니다. 예를 들어, 0은 가장 마지막 문자를 추출하고, -1이면 그 문자열의 마지막 문자로부터 1만큼 왼쪽으로 떨어져 있다고 간주됩니다. (그러나 StartingPos가 문자열의 왼쪽 끝을 넘어서 시도하면, 첫 문자부터 추출을 시작합니다).

Length

If this parameter is omitted, it defaults to "all characters". Otherwise, specify the maximum number of characters to retrieve (fewer than the maximum are retrieved whenever the remaining part of the string is too short). You can also specify a negative Length to omit that many characters from the end of the returned string (an empty string is returned if all or too many characters are omitted).

반환 값

This function returns the requested substring of String.

논평

Functionally, the SubStr function is almost the same as the StringMid command. However, it's recommended to use SubStr, because it is more flexible and future-proofed than StringMid.

RegExMatch(), StringMid, StringLeft/Right, StringTrimLeft/Right

예제

Retrieves a substring with a length of 3 characters at position 4.

MsgBox % SubStr("123abc789", 4, 3) ; Returns abc

Retrieves a substring from the beginning and end of a string.

String := "The Quick Brown Fox Jumps Over the Lazy Dog"
MsgBox % SubStr(String, 1, 19)  ; Returns "The Quick Brown Fox"
MsgBox % SubStr(String, -7)  ; Returns "Lazy Dog"