Page 1 of 1

How can I replace numeric entities in a string?

Posted: 12 May 2015 14:00
by pjj
I'm cleaning up a document, which has plenty of "&x160;" (=non-breaking space) entities; I want to replace them with regular spaces. When I try

Code: Select all

Document.ReplaceAll(" ", " ", false, false, false);
search results panel opens up, telling me that "0 items found in 0 of 1 searched files" (sic!). Searching for a "regular" string I get correct message ("in 1 of 1 searched files".)
When I try

Code: Select all

Document.SelectAll;
s = Document.SelText;
s = ScriptUtils.StringReplaceAll(s, " ", " ");
Document.SelText = s;
nothing is replaced, either.

My guess is that this &x160; should be escaped somehow, but how exactly? When I search for &x160 instead (no closing semicolon) with StringReplaceAll(), I get a message
"160" is not a valid integer value

Re: How can I replace numeric entities in a string?

Posted: 12 May 2015 14:40
by micha_he
Maybe...

Edit - New try:

Code: Select all

s = ScriptUtils.RegExReplaceAll(s, "\xA0", " ");

Re: How can I replace numeric entities in a string?

Posted: 12 May 2015 14:53
by pjj
Vielen Dank, aber es funktioniert nicht :(

Does it work for you? I have literal strings   (6 chars), not just single entities with code no. 160.

OK, I can replace it in two steps:

Code: Select all

s = ScriptUtils.StringReplaceAll(s, "&#", "");
s = ScriptUtils.StringReplaceAll(s, "160;", " ");
but to be on a safe side I should probably use something like this:

Code: Select all

s = ScriptUtils.StringReplaceAll(s, "&#", "$$$");
s = ScriptUtils.StringReplaceAll(s, "$$$160;", " ");

Re: How can I replace numeric entities in a string?

Posted: 12 May 2015 15:17
by micha_he
Same here ! Maybe an error...
But you can use:

Code: Select all

s = ScriptUtils.RegExReplaceAll(s, "&(#)160;", " ");

Re: How can I replace numeric entities in a string?

Posted: 12 May 2015 15:58
by Rickard Johansson
It's a bug. I've fixed it in the next release.