5

Postscript で 2 つの文字列を連結するにはどうすればよいですか?

(foo) (bar) ??? -> (foobar)
4

3 に答える 3

9

PostScriptには、組み込みの文字列連結演算子はありません。そのためのコードを書く必要があります。例えば

 /concatstrings % (a) (b) -> (ab)  
   { exch dup length    
     2 index length add string    
     dup dup 4 2 roll copy length
     4 -1 roll putinterval
   } bind def  

( https://en.wikibooks.org/wiki/PostScript_FAQ/Programming_PostScript#How_to_concatenate_strings%3Fからのコード。 )

于 2012-09-12T00:02:57.703 に答える
6

任意の数の文字列に一般化された同じアイデア。acat以前のリビジョンでは、文字列の配列を取るヘルパー関数を使用しています (カウントと反復を簡単にするため)。このバージョンでは、より手の込んだループとスタック操作を使用して、配列の割り当てを回避しています。stringこのバージョンでは、演算子を に変更して配列も連結しますarray

% (s1) (s2) (s3) ... (sN) n  ncat  (s1s2s3...sN)
/ncat {        % s1 s2 s3 .. sN n                   % first sum the lengths
    dup 1 add  % s1 s2 s3 .. sN n n+1 
    copy       % s1 s2 s3 .. sN n  s1 s2 s3 .. sN n
    0 exch     % s1 s2 s3 .. sN n  s1 s2 s3 .. sN 0 n 
    {   
        exch length add 
    } repeat             % s1 s2 s3 .. sN  n   len  % then allocate string
    string exch          % s1 s2 s3 .. sN str   n   
    0 exch               % s1 s2 s3 .. sN str  off  n
    -1 1 {               % s1 s2 s3 .. sN str  off  n  % copy each string
        2 add -1 roll       % s2 s3 .. sN str  off s1  % bottom to top
        3 copy putinterval  % s2 s3 .. sN str' off s1
        length add          % s2 s3 .. sN str' off+len(s1)
                            % s2 s3 .. sN str' off'
    } for                               % str' off'
    pop  % str'
} def 

(abc) (def) (ghi) (jkl) 4 ncat == %(abcdefghijkl)
于 2012-09-18T08:05:01.467 に答える
3

便利なサブルーチンがあります

http://www.jdawiseman.com/papers/placemat/placemat.ps

(2 つの文字列をConcatenate受け入れる) とConcatenateToMark(マーク string0 string1 …) を含みます。

于 2013-04-01T09:22:15.047 に答える