문자열을 주어진 문자로 배열로 분할하는 가장 쉬운 방법은 무엇입니까? 예를 들어, 공간을 통해 분할하여 단어 배열 만들기; 또는 문자열의 모든 문자 배열을 만드는 것입니다.문자열을 포스트 스크립트에서 배열로 분할하는 방법
제가 생각할 수있는 유일한 방법은 search
을 루프로 사용하는 것입니다. 모든 언어에는이 목적을위한 함수가 있으므로, PostScript
에 함수가 없기 때문에 두려워합니다.
문자열을 주어진 문자로 배열로 분할하는 가장 쉬운 방법은 무엇입니까? 예를 들어, 공간을 통해 분할하여 단어 배열 만들기; 또는 문자열의 모든 문자 배열을 만드는 것입니다.문자열을 포스트 스크립트에서 배열로 분할하는 방법
제가 생각할 수있는 유일한 방법은 search
을 루프로 사용하는 것입니다. 모든 언어에는이 목적을위한 함수가 있으므로, PostScript
에 함수가 없기 때문에 두려워합니다.
당신은 search
연산자로 올바른 길을 가고 있습니다. 텍스트 문자열 검색 및 일치를 수행하는 것이 목적입니다.
search string seek search post match pre true (if found)
string false (if not found)
looks for the first occurrence of the string seek within string and
returns results of this search on the operand stack. The topmost
result is a boolean that indicates if the search succeeded.
If search finds a subsequence of string whose elements are equal
to the elements of seek, it splits string into three segments:
pre, the portion of string preceding the match; match, the portion
of string that matches seek; and post, the remainder of string. It
then pushes the string objects post, match, and pre on the operand
stack, followed by the boolean true. All three of these strings are
substrings sharing intervals of the value of the original string.
If search does not find a match, it pushes the original string
and the boolean false.
Example:
(abbc) (ab) search ==> (bc) (ab) () true
(abbc) (bb) search ==> (c) (bb) (a) true
(abbc) (bc) search ==>() (bc) (ab) true
(abbc) (B) search ==> (abbc) false
%!
%(string) (delimiter) split [(s)(t)(r)(i)(n)(g)]
/split { % str del
[ 3 1 roll % [ str del
{ % [ ... str del
search { % [ ... post match pre
3 1 roll % [ ... pre post match %ie. [ ... pre str' del
}{ % [ ... str
exit % [ ... str %% break-from-loop
}ifelse
}loop % [ ...
] % [ ... ]
} def
(string of words separated by spaces)()split ==
%-> [(string) (of) (words) (separated) (by) (spaces)]
(string.of.words.separated.by.dots)(.)split ==
%-> [(string) (of) (words) (separated) (by) (dots)]
내가 여기 내 대답에 루프 검색을 사용의 예를 가지고 : 다음은 PostScript Language Reference Manual에있는
search
운영자 요약 한 것입니다 http://stackoverflow.com/a/5846955/733077 –