[plt-scheme] problem with string
besson baptiste wrote:
> This is suppose to cast val into a string padded to
> the length of exp.
> for ex:
> (str$ 176 4) should return \0176
> instead I always get two zero 00 before val
>
>>(str$ 176 4)
>
> "\000176"
>
> but I get
>
>
>>(string-length (str$ 176 4))
>
> 4
>
> which is what I want.
> I don't understand why is these 00 appear for any
> value of val and exp.
Chapter 14 of the PLT MzScheme: Language Manual has the following:
Within string constants, the following escape sequences are recognized in addition to \" and \\:
* \a: alarm (ASCII 7)
* \b: backspace (ASCII 8)
* \t: tab (ASCII 9)
* \n: linefeed (ASCII 10)
* \v: vertical tab (ASCII 11)
* \f: formfeed (ASCII 12)
* \r: return (ASCII 13)
* \e: escape (ASCII 27)
* \o, \oo, or \ooo: ASCII for octal o, oo, or ooo, where each o is 0, 1, 2, 3, 4, 5, 6, or 7. The \ooo form takes
precedence over the \oo form, and \oo takes precedence over \o.
* \xh or \xhh: ASCII for hexadecimal h or hh, where each h is 0, 1, 2, 3, 4, 5, 6, 7, a, A, b, B, c, C, d, D, e, E, f,
or F. The \xhh form takes precedence over the \xh form.
Furthermore, a backslash followed by a linefeed, carriage return or return-linefeed combination is elided, allowing
string constants to span lines. Any other use of backslash within a string constant is an error.
The import one here is the \ooo which means that \000 is parsed as the char with the ascii-number 0.
I.e. the external syntax \000 represent one char.
--
Jens Axel Søgaard