* Re: How to replace a string to Unicode escape?
[not found] <mailman.10812.1258387082.2239.help-gnu-emacs@gnu.org>
@ 2009-11-16 21:22 ` harven
2009-11-17 3:24 ` ptmono
0 siblings, 1 reply; 3+ messages in thread
From: harven @ 2009-11-16 21:22 UTC (permalink / raw)
To: help-gnu-emacs
ptmono <ptmono@gmail.com> writes:
> A program returns a unicode value "%uc0ac%ub791". The value can be the
> combination of unicode with ascii. For example "%uc0ac%ub791 sarang
> %uc0ac%ub791".
>
> The function string-to-multibyte can be used to return the string.
>
> ,----
> | (string-to-multibyte "\uc0ac\ub791 sarang \uc0ac\ub791")
> | "사랑 sarang 사랑"
> `----
>
> The *problem* is that how to replace "%" to "\" or "%u" to "\u".
Here is a ugly hack (use at your own risk)
(defun my-ucs (arg)
"return unicode character \\uxxxx from string \"%uxxxx\" or return \"\".
probably fails badly if xxx is not a valid hex code"
(or
(char-to-string
(decode-char 'ucs
(string-to-number
(substring arg 2) 16)))
""))
(replace-regexp-in-string
"%u...."
'my-ucs
"%uc0ac%ub791 sarang %uc0ac%ub791")
--> "사랑 sarang 사랑"
Cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to replace a string to Unicode escape?
2009-11-16 21:22 ` How to replace a string to Unicode escape? harven
@ 2009-11-17 3:24 ` ptmono
0 siblings, 0 replies; 3+ messages in thread
From: ptmono @ 2009-11-17 3:24 UTC (permalink / raw)
To: help-gnu-emacs
Thanks.
harven <harven@free.fr> writes:
> Here is a ugly hack (use at your own risk)
>
> (defun my-ucs (arg)
> "return unicode character \\uxxxx from string \"%uxxxx\" or return \"\".
> probably fails badly if xxx is not a valid hex code"
> (or
> (char-to-string
> (decode-char 'ucs
> (string-to-number
> (substring arg 2) 16)))
> ""))
>
> (replace-regexp-in-string
> "%u...."
> 'my-ucs
> "%uc0ac%ub791 sarang %uc0ac%ub791")
>
> --> "사랑 sarang 사랑"
>
> Cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
* How to replace a string to Unicode escape?
@ 2009-11-16 14:46 ptmono
0 siblings, 0 replies; 3+ messages in thread
From: ptmono @ 2009-11-16 14:46 UTC (permalink / raw)
To: help-gnu-emacs
A program returns a unicode value "%uc0ac%ub791". The value can be the
combination of unicode with ascii. For example "%uc0ac%ub791 sarang
%uc0ac%ub791".
The function string-to-multibyte can be used to return the string.
,----
| (string-to-multibyte "\uc0ac\ub791 sarang \uc0ac\ub791")
| "사랑 sarang 사랑"
`----
The *problem* is that how to replace "%" to "\" or "%u" to "\u".
How can return the string from the value?
Thanks
P.S
,----
| (string-to-multibyte "\\uc0ac\\ub791 sarang \\uB098\\uB2E4")
| "\\uc0ac\\ub791 sarang \\uB098\\uB2E4"
|
| (replace-regexp-in-string "%u" "\\u" "%uc0ac%ub791 sarang %uc0ac%ub791")
| ->>>(error "Invalid use of `\\' in replacement text")
|
| (replace-regexp-in-string "%" "\\\\" "%uc0ac%ub791 sarang %uc0ac%ub791")
| "\\uc0ac\\ub791 sarang \\uc0ac\\ub791"
`----
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-11-17 3:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.10812.1258387082.2239.help-gnu-emacs@gnu.org>
2009-11-16 21:22 ` How to replace a string to Unicode escape? harven
2009-11-17 3:24 ` ptmono
2009-11-16 14:46 ptmono
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.