I am generating a Word doc in xml based on customer input, and of course it blows up whenever an &
is used. I tried replacing all instances of &
with &
, but then &
literally shows up in my Word Doc. Here's my code:
static String replac开发者_JS百科e(String in) {
String ampersand = "&(?![a-zA-Z][a-zA-Z][a-zA-Z]?[a-zA-Z]?;)";
return in.replaceAll(ampersand,"&");
}
Any ideas?
The problem is that the ampersand is escaped differently in TOC and the title.
In TOC, it is escaped as &
while in the title is escaped as \u0026
.
Solution is to escape ampersand differently in TOC and title:
- TOC: html escaping sequence
- TITLE: unicode escape sequence.
Have you tried replacing the ampersand with &
or &
(unicode)?
Word 2007 itself does &, so your problem must be something else.
Your regular expressions seems wrong to me. Why don't you just do:
static String replace(String in) {
return in.replace("&","&");
}
精彩评论