stringcharasciipostscript

How to get the nth character of string in Postscript


I`m new to Postscript, and I was wondering how to get the nth character of a string in postscript.

If I do something like

(hello) 1 get

then 101 is pushed on the stack (ASCII 101 corresponds to "e")

how to convert that 101 to the corresponding "e" character as string (e)?

or how to compare it to a string (e) such that i can tell it is in fact some char 'e'?

so how to say something like 101 === (e) ?


Solution

  • I am somewhat confused by your output as ASCII 'e' should be 101 according to every source I have at hand including running your code using gs. That said you probably want to use getinterval instead of get as it returns a string.

    (hello) 1 1 getinterval