guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there any thing to convert string encording?


From: Mark H Weaver
Subject: Re: Is there any thing to convert string encording?
Date: Fri, 23 Nov 2012 09:49:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

nalaginrut <address@hidden> writes:
> In ruby, we can use force_encoding to convert the encoding of a string:
> "abc\u{6666}".force_encoding("UTF-8")

Byte sequences have an encoding, but Scheme strings are a higher-level
concept.  In Scheme, a string is a sequence of Scheme characters
(Unicode scalar values), and thus they do not have an encoding[1].

If you need to control the encoding used to write strings to a port,
then use 'set-port-encoding!'.

If you want to inspect and/or manipulate individual bytes, then you can
use a bytevector, as suggested by Noah.

Noah Lavine <address@hidden> writes:
> In that case I believe you want to put the bits you're interested in
> in a bytevector, and use utf8->string, utf16->string, or
> utf32->string.

Those convert from bytevectors to strings.  To convert from strings to
bytevectors, use 'string->utf8', 'string->utf16', or 'string->utf32'.

    Regards,
      Mark


[1] Scheme strings have an internal representation, but that's neither
    visible nor changeable by the user.  They are currently implemented
    as C arrays of Unicode scalar values, but that might change in the
    future.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]