在後記中,cvs * 運算符 *被稱爲將數字轉換爲字符串。我應該如何使用它? 我想:後記:如何將整數轉換爲字符串?
100 100 moveto
3.14159 cvs show
或
100 100 moveto
3.14159 cvs string show
,但沒有奏效。
任何幫助?
在後記中,cvs * 運算符 *被稱爲將數字轉換爲字符串。我應該如何使用它? 我想:後記:如何將整數轉換爲字符串?
100 100 moveto
3.14159 cvs show
或
100 100 moveto
3.14159 cvs string show
,但沒有奏效。
任何幫助?
嘗試3.14159 20 string cvs show
。
string
需要一個大小,並將創建的字符串留在堆棧上。 cvs
需要一個值和一個字符串來存儲轉換後的值。
如果你正在做大量的字符串轉換的,它可能是更有效的創建一個字符串,並在每個轉換重複使用它:
/s 20 string def
3.14159 s cvs show
一個常見的成語是使用一個字符串作爲模板。
1.42857 ( ) cvs show
您甚至可以通過呈現具有較大字符串的各種子字符串的cvs來執行格式化輸出。
%.......
(2/7 = ) dup 6 7 getinterval
2.85714 exch cvs pop show
但是Ghostscript Style Guide禁止這樣做。這幾乎是我們唯一發布的Postscript風格指南。 (在comp.lang.postscript中爲A discussion about this)。所以一個常見的建議是在你需要時分配一個新的字符串,並讓垃圾收集器保留它。
4.28571 7 string cvs show
作爲最後的手段,真正的懶惰黑客劫持=string
,內置使用=
和==
輸出數(使用,當然,我們的朋友cvs
),128字節的緩衝區。
5.71428 =string cvs show
,如果你喜歡的那一個,你可以用=
的其他技巧結合起來:立即求名。
{ 7.14285 //=string cvs show } % embed =string in this procedure
這會削減額外的微秒,並且使交互式檢查代碼變得更加困難。在此過程中調用==
將不會顯示您正在使用=string
;它看起來就像其他任何字符串一樣。
該包的另一個伎倆是從a post by Helge Blischke in comp.lang.postscript。這是一個獲得零填充整數的簡單方法。
/bindec % <integer> bindec <string_of_length_6>
{
1000000 add 7 string cvs 1 6 getinterval
}bind def
「1000000 add 7 string cvs 1 6 getinterval」 - Neat trick :-) –