[topic] 末尾の空白文字を取り除く

与えられた文字列の末尾の空白文字を取り除く方法と、その操作が与えられた文字列を破壊するかどうか。取り除かれる空白文字の種類。

Posted feedbacks - PostScript

手頃なオペレータがなかったので自作。取り除く文字は5行目で定義しています。 返り値はもとの文字列の部分文字列(参照)です。 元の文字列実体が保持される、という意味では非破壊です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
%!PS

/RTrim { % (String   ) RTrim (String)
    dup length 1 sub
    <<9 true 10 true 11 true 12 true 13 true 32 true>>
    3 1 roll
    -1 0 {
        2 copy get
        3 index exch known {
            0 exch getinterval
        } {pop exit} ifelse
    } for
    exch pop
} bind def

(|) print
(ABCD   ) RTrim print
(|) =

Index

Feed

Other

Link

Pathtraq

loading...