Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7915
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: unicode |
| Date | 2011-09-12 14:04 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j4ls4c$pa8$1@dont-email.me> (permalink) |
| References | <6c991195-ab57-417c-92e0-6d5ee1c451dc@dq7g2000vbb.googlegroups.com> |
On 9/12/2011 12:24 PM, bob wrote:
> Why does Java complain when I do this?
>
> html = html.replaceAll("\u000A", " ");
>
> This one works:
>
> // nbsp
> html = html.replaceAll("\u00A0", " ");
That was interesting. From the docs on java.util.regex.Pattern;
"Comparison to Perl 5
The Pattern engine performs traditional NFA-based matching with ordered
alternation as occurs in Perl 5.
Perl constructs not supported by this class:
.
.
.
The preprocessing operations \l \u, \L, and \U."
You can however do this, which is even more interesting!
public class test {
public static void main(String[] args) {
String html = "hello world!\n";
html = html.replaceAll("\\x{a}","~");
System.out.println(html);
}
}
C:\Documents and Settings\Knute Johnson>java test
hello world!~
From the Java Language Specification
"Because Unicode escapes are processed very early, it is not correct to
write "\u000a" for a string literal containing a single linefeed (LF);
the Unicode escape \u000a is transformed into an actual linefeed in
translation step 1 (§3.3) and the linefeed becomes a LineTerminator in
step 2 (§3.4), and so the string literal is not valid in step 3.
Instead, one should write "\n" (§3.10.6). Similarly, it is not correct
to write "\u000d" for a string literal containing a single carriage
return (CR). Instead use "\r"."
And there you have it!
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
unicode bob <bob@coolgroups.com> - 2011-09-12 12:24 -0700
Re: unicode Knute Johnson <nospam@knutejohnson.com> - 2011-09-12 14:04 -0700
Re: unicode Roedy Green <see_website@mindprod.com.invalid> - 2011-09-12 14:08 -0700
Re: unicode Arne Vajhøj <arne@vajhoej.dk> - 2011-09-12 17:31 -0400
Re: unicode markspace <-@.> - 2011-09-12 16:33 -0700
Re: unicode Lew <lewbloch@gmail.com> - 2011-09-12 17:46 -0700
Re: unicode markspace <-@.> - 2011-09-12 20:16 -0700
Re: unicode Roedy Green <see_website@mindprod.com.invalid> - 2011-09-12 22:05 -0700
Re: unicode Roedy Green <see_website@mindprod.com.invalid> - 2011-09-12 22:10 -0700
Re: unicode Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-09-13 07:18 +0000
Re: unicode Arne Vajhøj <arne@vajhoej.dk> - 2011-09-12 20:57 -0400
Re: unicode markspace <-@.> - 2011-09-12 19:51 -0700
Re: unicode Arne Vajhøj <arne@vajhoej.dk> - 2011-09-13 20:17 -0400
Re: unicode markspace <-@.> - 2011-09-13 19:32 -0700
Re: unicode Roedy Green <see_website@mindprod.com.invalid> - 2011-09-14 11:49 -0700
Re: unicode Paul Cager <paul.cager@googlemail.com> - 2011-09-13 04:05 -0700
Re: unicode Roedy Green <see_website@mindprod.com.invalid> - 2011-09-12 22:02 -0700
Re: unicode Arne Vajhøj <arne@vajhoej.dk> - 2011-09-13 20:30 -0400
Re: unicode Arne Vajhøj <arne@vajhoej.dk> - 2011-09-12 17:29 -0400
Re: unicode Lew <lewbloch@gmail.com> - 2011-09-12 15:48 -0700
csiph-web