Как разбить строку на массив в PostScript

Как проще всего разбить строку на массив по заданному символу? Например, создание массива слов путем разделения по пробелу; или даже сделать массив из всех символов строки.

Единственный способ, который я могу придумать, - это использовать search в цикле. Поскольку во всех языках есть функция для этой цели, я боюсь, что мне не хватает функции в PostScript для этого.


person Googlebot    schedule 07.09.2012    source источник
comment
У меня есть пример использования поиска в цикле в моем ответе здесь: stackoverflow.com/a/5846955/733077   -  person luser droog    schedule 12.09.2012


Ответы (1)


Вы на правильном пути с оператором search. Его целью является поиск и сопоставление текстовых строк. Вот краткое описание оператора search, которое можно найти в Справочном руководстве по языку PostScript:

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  
person Dave M    schedule 08.09.2012