Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #17106

Re: retriving escape unicode sequences from files ...

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.lang.java.programmer
Subject Re: retriving escape unicode sequences from files ...
References <jvfhtb$gh$1@speranza.aioe.org> <501c6edc$0$283$14726298@news.sunsite.dk>
Message-ID <ZY0Tr.68707$iI7.884@newsfe03.iad> (permalink)
Date 2012-08-03 20:49 -0700

Show all headers | View raw


On 8/3/12 5:37 PM, Arne Vajhøj wrote:
> On 8/2/2012 11:52 PM, qwertmonkey@syberianoutpost.ru wrote:
>>   Why is it that if you save a unicode sequence in a file, say "français"
>> ~
>> \u0066\u0072\u0061\u006e\u00e7\u0061\u0069\u0073
>> ~
>>   and then retrieve as a String you can't then convert it back to a
>> UTF-8 String
>> ~
>
> Some code from my shelf:
>
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
>
> public class Unescape {
>      private static final Pattern p =
> Pattern.compile("\\\\u([0-9A-F]{4})");
>      public static String U2U(String s) {
>          String res = s;
>          Matcher m = p.matcher(res);
>          while(m.find()) {
>              res = res.replaceAll("\\" + m.group(0),
> Character.toString((char)Integer.parseInt(m.group(1), 16)));
>          }
>          return res;
>      }
>      public static void main(String[] args) {
>
> System.out.println(U2U("\\u0041\\u0042\\u0043\\u000A\\u0031\\u0032\\u0033"));
>
>      }
> }
And if you wanted this to be effecient, you'd use appendReplacement 
instead of res.replaceAll()

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

retriving escape unicode sequences from files ... qwertmonkey@syberianoutpost.ru - 2012-08-03 03:52 +0000
  Re: retriving escape unicode sequences from files ... markspace <-@.> - 2012-08-02 21:00 -0700
  Re: retriving escape unicode sequences from files ... Roedy Green <see_website@mindprod.com.invalid> - 2012-08-03 01:35 -0700
  Re: retriving escape unicode sequences from files ... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-08-03 23:23 +0000
  Re: retriving escape unicode sequences from files ... Arne Vajhøj <arne@vajhoej.dk> - 2012-08-03 20:37 -0400
    Re: retriving escape unicode sequences from files ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-03 20:49 -0700
      Re: retriving escape unicode sequences from files ... markspace <-@.> - 2012-08-03 21:13 -0700
        Re: retriving escape unicode sequences from files ... Lew <lewbloch@gmail.com> - 2012-08-03 23:45 -0700
      Re: retriving escape unicode sequences from files ... Arne Vajhøj <arne@vajhoej.dk> - 2012-08-06 22:32 -0400

csiph-web