% (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)
3 回答
PostScript没有内置的字符串连接运算符 . 你需要为此编写一些代码 . 例如,请参阅http://en.wikibooks.org/wiki/PostScript_FAQ#How_to_concatenate_strings.3F .
(由mh更新:复制到这里)
同样的想法推广到任意数量的字符串 . 早期版本使用辅助函数
acat
,它接受一个字符串数组(以便于计数和迭代) . 此版本使用更高级的循环和堆栈操作来避免分配数组 . 此版本还可以通过将string
运算符更改为array
来连接数组 .有很多有用的子程序
包括
Concatenate
(接受两个字符串)和ConcatenateToMark
(标记string0 string1 ...) .