REXX 문자열 조작 명령을 사용 하 여

만료된 KB 콘텐츠 고지 사항

이 문서는 Microsoft에서 더 이상 지원하지 않는 제품에 대해 작성되었습니다. 따라서 이 문서는 “있는 그대로" 제공되며 더 이상 업데이트되지 않습니다.


여기서는 REXX 프로그래밍 언어의 문자열 조작 기능을 나열 하 고 예제를 제공 합니다.

자세한 내용

부인:이 기사는; 제공 하는 정보를 사용 하 여 프로그램을 개발할 수 있는 사용자를 위해 제공 됩니다. 언어 있지만 대신 간단한 루틴을 작성 누군가 지원 하기 위해 빠르게 참조할 광범위 한 처리 않습니다. Microsoft 재현 하 고 자체는 언어 구현 문제 제출 넘어 프로그래밍 노력을 지원할 수 없습니다. 추가 지원, REXX 참조 해야 할 경우 참조 "REXX 언어, 프로그래밍에 대 한 실용적인 접근법" 달력이 F. Cowlishaw가 같은 Prentice 홀, Englewood 절벽, 1985.

목록의 맨 아래에 예제가 제공 됩니다. 중괄호 ({}) 주석을 나타내는 데 사용 됩니다.
ABBREV(string, test_str, length)

{ If test_str is the same as the leading characters of string and
test_str is at least "length" long then ABBREV returns 1, otherwise
zero. }

CENTER(string, final_length, pad_character_if_needed)

{ Center the string in a final_length field padded on each sides
with the specified character if needed. If the string is longer
than the final_length characters will be truncated from each end. }

COMPARE(string1, string2, pad)

{ Returns zero or the position of the first non-match. For
differing length strings "pad" is compared to the remaining part of
the longer string. The default for "pad" is space. }

COPIES(source_string, number)

{ Creates a new string of "number" repetitions of source_string. }

DELSTR(string, start_position, number_of_bytes_to_delete)

{ Returns a string with the number of bytes deleted at the start
position but does not alter "string" itself. }

DELWORD(string_of_words, start_word, #_of_words_to_delete)

{ Same as DELWORD except on the word level. If the number of words
is not specified then delete to end-of-line. }

INSERT(source, target, start, length, pad_character)

{ Insert "length" of the source into the target at the position
specified by "start" padding with pad_character if necessary. }

LASTPOS(find_this, target_string, search_backward_from_here)

{ Search backward from the end of target_string or specified
position looking for find_this and return the position or zero if
not found. }

LEFT(of_this_string, for_this_length, pad_with_this_if_reqd)

{ Returns the leftmost bytes from of_this_string and pads the end
with pad_with_this_if_reqd to produce a string of for_this_length
bytes. }


{ returns the length of the specified string. }

OVERLAY(source, target, start_point, length, pad_with_this)

{ returns a target of "length" plus start_point minus one (padded
with pad_with_this if necessary) with source inserted at
start_point. }

PARSE [UPPER] [options] [WITH] var1 var2 var3 ... var?|template

{ Parses, optionally uppercasing (with UPPER), the supplied
[options] placing the result into one or more variables. [options]
are: ARG, PULL, LINEIN, SOURCE, VALUE expression, VAR name, or
VERSION. For ARG, PULL, LINEIN, and VALUE, see their descriptions
in the REXX articles for more information. SOURCE returns the
operating system (OS/2), source of execution (typically COMMAND for
the command prompt), and name of the currently executing REXX file
(*.CMD). VAR name instructs PARSE to parse the named variable.
VERSION returns the REXX product name, version and date. The
expression used with VALUE can be a built-in function such as
DATE(). WITH can be used in such a way that it breaks a string into
its components (as follows): PARSE VAR source_string first_word
source_string. "template" is a combination of variables and
literals, if literals are supplied they control how variables are
assigned their contents, see example. }

POS(find_this, target_string, start_position)

{ Searches target_string for find_this and returns either the
located position or zero if find_this is not found. }


{ Returns the string in reversed (the last byte is first, etc.)
order. }

RIGHT(string, length, pad)

{ Returns the rightmost characters of "string" up to "length".
"pad" will be used to prepend to string if it is shorter than
"length". }

SPACE(string, n, pad_character)

{ Isolates words in a string and returns a reconstructed string
containing the words (in the same order) separated by "n" spaces or
pad_characters. "n" defaults to 1. }

STRIP(string,'L'|'T'|'B', optional_character_to_strip)

{ Strips 'L'eading, 'T'railing, or 'B'oth leading and trailing
spaces (or optional_character_to_strip if specified) from string. }

SUBSTR(string, start_position, length, pad_with_this)

{ Returns a portion of "string" beginning at start_position which
is "length" long, "length" is either satisfied from "string" itself
or by padding the result with "pad_with_this". }

SUBWORD(string, start_word, number_of_words)

{ This command is virtually identical to SUBSTR except that words,
not characters, are specified by parameters 2 and 3. }

TRANSLATE(string, replace_with, replace_this)

{ Returns a string with any characters in replace_this changed to
their corresponding characters in replace_with. For example,
TRANSLATE("This is a test", "123", "iae") would produce "Th1s 1s 2
t3st". }

VERIFY(string, reference_list, 'M'|'N', start_position)

{ Returns the position in string of the first character that either
'M'atchs or does 'N'ot match the characters in reference_list
(depending on whether 'M' or 'N' was specified). Otherwise a zero
is returned. The check can be restricted to begin at
start_position. }

WORD(string, word_number)

{ Returns the word_number'd word or nothing if word_number exceeds
the number of the last word in the string. }

WORDINDEX(string, word_number)

{ Returns the character position of the word_number word in string.

WORDLENGTH(string, word_number)

{ Returns the length of the word_number word in string. }

WORDPOS(word|phrase, string, start_position)

{ Returns the number of the first (or only) word in phrase relative
to the start of the string, start_position can be specified as the
word number to begin with, a zero return means not found. }


{ Returns the number of words in a string. }

다음 예입니다. REXX 프로그램을 만들고 실행 하 여 결과 볼.
x = "The quick brown fox jumps over the lazy dog"say 'x = ' x
say "ABBREV(x, 'The quick',8) returns:"
say ABBREV(x, 'The quick',8)
say "ABBREV(x, 'The quick',12) returns:"
say ABBREV(x, 'The quick',12)
say "CENTER(' This ',10,'!') does: " CENTER('This',10,'!')
say "COMPARE('abcde','abcdf') returns:"
say COMPARE('abcde','abcdf')
say "COMPARE('abcde','abcde') returns:"
say COMPARE('abcde','abcde')
say "COMPARE('abcde','abcd',' ') returns:"
say COMPARE('abcde','abcd',' ')
say "COMPARE('abcd ','abcd',' ') returns:"
say COMPARE('abcd ','abcd',' ')
say "COPIES('123',5) returns " COPIES('123',5)
say "DELSTR(x,5,6) returns:"
say DELSTR(x,5,6)
say "DELWORD(x,4,2) returns:"
say DELWORD(x,4,2)
say 'x = ' x
say "INSERT('!',x,5,3,'*') returns:"
say INSERT('!',x,5,3,'*')
say "POS('fox',x) returns " POS('fox',x)
say "POS('fox',x,18) returns " POS('fox',x,18)
say "LASTPOS('e',x) returns " LASTPOS('e',x)
say "LASTPOS('e',x,10) returns " LASTPOS('e',x,10)
say "LEFT(x,19) returns " LEFT(x,19)
say "LEFT(x,50,'-') returns " LEFT(x,50,'-')
say "LENGTH(x) returns " LENGTH(x)
say "OVERLAY('XXX',x,11,5,'&') returns:"
say OVERLAY('XXX',x,11,5,'&')
say "REVERSE(x) returns:"
say REVERSE(x)
say "RIGHT(x,8) returns " RIGHT(x,8)
say "RIGHT(x,50,'^') returns:"
say RIGHT(x,50,'^')
say 'x = ' x
y = 'This is a string'
say "y = 'This is a string' "
say "SPACE(y,2,'_') returns " SPACE(y,2,'_')
z = '*** Note this! ***'
say "z = '*** Note this! ***' "
say "STRIP(z,'L','*') returns " STRIP(z,'L','*')
say "STRIP(z,'T','*') returns " STRIP(z,'T','*')
say "STRIP(z,'B','*') returns " STRIP(z,'B','*')
say "SUBSTR(x,21,5) returns " SUBSTR(x,21,5)
say "SUBSTR(x,41,15, '#') returns " SUBSTR(x,41,15,'#')
say "SUBWORD(x,5,2) returns " SUBWORD(x,5,2)
say "TRANSLATE(x,'W','e') returns:"
say TRANSLATE(x,'W','e')
say "VERIFY(x,'obfj','M') returns " VERIFY(x,'obfj','M')
say "VERIFY(x,'Thequickbrownfox','N') returns:"
say VERIFY(x,'Thequickbrownfox','N')
say "WORD(x,7) returns " WORD(x,7)
say "WORDINDEX(x,3) returns " WORDINDEX(x,3)
say "WORDINDEX(x,10) returns " WORDINDEX(x,10)
say "WORDLENGTH(x,4) returns " WORDLENGTH(x,4)
say 'x = ' x
say "WORDPOS('fox jumps',x) returns " WORDPOS('fox jumps',x)
say "WORDPOS('fox jumps',x,6) returns:"
say WORDPOS('fox jumps',x,6)
say "WORDS(x) returns " WORDS(x)
say "The following are parsing examples"
say "parse SOURCE example"
parse SOURCE word1 word2 word3 word4
say "Saying parsed words"
say word1
say word2
say word3
say word4
say "Parsing the words in x"
parse VAR x word1 word2 word3 word4 word5 word6
say "saying the first 6 words in x"
say word1
say word2
say word3
say word4
say word5
say word6
say "parse version returns:"
parse version word1 word2 word3 word4 word5
say "Saying parsed words"
say word1
say word2
say word3
say word4
say word5
say "Parsing the date() function"
parse value date() with day month year
say "Year is " year
say "Month is " month
say "Day is " day
say "Parsing with a template"
y = 'Parse w/ template, use literals - see: Powerful! Yes?
parse VAR y var1 '/' var2 ',' var3 '-' var4 ':' var5 '!'
var6 '?' var7
say "Showing variables"
say var1
say var2
say var3
say var4
say var5
say var6
say var7


문서 ID: 99066 - 마지막 검토: 2017. 1. 12. - 수정: 1