Are file-port and string-port much different? I can convert strings in file
but I want not to use file. My terminal charset is utf-8. Suppose there be
a "XXX" encoded text file "a.txt", it would be converted like this:
(use-modules (ice-9 rdelim))
(set-port-encoding! (current-output-port) "utf-8")
(define port (open-input-file "a.txt"))
(set-port-encoding! port "XXX")
(display (read-delimited "" port))
(close-port port)
I tried similar manner with string-port but failed. In real case, there is
"XXX" encoded string. In this case, I cannot prepare it, so read it from a
file.
(use-modules (ice-9 rdelim))
(define port (open-input-file "a.txt"))
(set-port-encoding! port "XXX")
(let ((port1 (open-input-string (let ((str (read-delimited "" port)))
(close-input-port port)
str)))
(port2 (open-output-string)))
(set-port-encoding! port1 "XXX")
(set-port-encoding! port2 "utf-8")
(display (read-delimited "" port1) port2)
(close-input-port port1)
(display (get-output-string port2))
(close-output-port port2))
2012/4/28 Sunjoong Lee <[email protected]>
>
> Now, I need to convert this contents body string to utf-8 but I don't know
> how. I think it would be with port i/o.
>