From: Matthias Wächter on 28 Jun 2010 10:44 On 28.06.2010 15:24, Benoit Daloze wrote: > On 28 June 2010 07:39, Markus Schirp <mbj(a)seonic.net> wrote: >> IMHO better than eval ;) > > str = '\u041f\u0440\u0438\u0432\u0435\u0442!' > p str.gsub(/\\u(\h{4})/) { > $1.to_i(16).chr('UTF-8') > } Don't forget that Unicode Code Points not only cover the BMP and can be up to 6 hex digits long [http://en.wikipedia.org/wiki/Unicode#Character_planes_and_blocks]. What do you do if the string contained some escaped backslashes, like in str = '\u041f\\u0440'? Does it contain Surrogates? – Matthias
First
|
Prev
|
Pages: 1 2 Prev: Happy Intransition Day! Next: About method naming convention with "!" |