Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
- Subject: Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
- From: Jon Nolan <email@hidden>
- Date: Wed, 30 Dec 2009 13:50:08 -0700
- Organization: Loch Garman
Amedeo Mantica wrote:
here the map...
On 30/dic/2009, at 21.10, Amedeo Mantica wrote:
Hello,
I remember that there is a class that strips those orrible Microsoft
Word bad characters ( some dashes and quotes )
Amedeo,
Here's a slightly more elaborate and perhaps more complete solution.
Tested, tried and true in production apps.
private static NSDictionary<String, String> gremlins;
public static NSDictionary<String, String> gremlins() {
if (gremlins == null) {
NSMutableDictionary<String, String> dict = new
NSMutableDictionary<String, String>();
// standard versions
dict.setObjectForKey(" ", Character.toString((char)194) +
Character.toString((char)160)); //
non-breaking space
dict.setObjectForKey("®", Character.toString((char)194) +
Character.toString((char)174)); //
registered trademark
dict.setObjectForKey("¼", Character.toString((char)194) +
Character.toString((char)188)); // 1/4
dict.setObjectForKey("½", Character.toString((char)194) +
Character.toString((char)189)); // 1/2
dict.setObjectForKey("¾", Character.toString((char)194) +
Character.toString((char)190)); // 3/4
dict.setObjectForKey("–", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)147)); // endash
dict.setObjectForKey("–", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)148)); // emdash
dict.setObjectForKey("‘", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)152)); // left
single quotation mark
dict.setObjectForKey("’", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)153)); // right
single quotation mark
dict.setObjectForKey("“", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)156)); // left
double quotation mark
dict.setObjectForKey("”", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)157)); // right
double quotation mark
dict.setObjectForKey("•", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)162)); // bullet
dict.setObjectForKey("…", Character.toString((char)226) +
Character.toString((char)128) + Character.toString((char)166)); // ellipsis
dict.setObjectForKey("™", Character.toString((char)226) +
Character.toString((char)132) + Character.toString((char)162)); // trademark
// serialized versions
dict.setObjectForKey(" ", "\\U00c2\\U00a0"); //
non-breaking space
dict.setObjectForKey("®", "\\U00c2\\U00ae"); //
registered trademark
dict.setObjectForKey("¼", "\\U00c2\\U00bc"); // 1/4
dict.setObjectForKey("½", "\\U00c2\\U00bd"); // 1/2
dict.setObjectForKey("¾", "\\U00c2\\U00be"); // 3/4
dict.setObjectForKey("–", "\\U00e2\\U0080\\U0093"); // endash
dict.setObjectForKey("–", "\\U00e2\\U0080\\U0094"); // emdash
dict.setObjectForKey("‘", "\\U00e2\\U0080\\U0098"); //
left single quotation mark
dict.setObjectForKey("’", "\\U00e2\\U0080\\U0099"); //
right single quotation mark
dict.setObjectForKey("“", "\\U00e2\\U0080\\U009c"); //
left double quotation mark
dict.setObjectForKey("”", "\\U00e2\\U0080\\U009d"); //
right double quotation mark
dict.setObjectForKey("•", "\\U00e2\\U0080\\U00a2"); // bullet
dict.setObjectForKey("…", "\\U00e2\\U0080\\U00a6"); //
ellipsis
dict.setObjectForKey("™", "\\U00e2\\U0084\\U00a2"); //
trademark
// done
gremlins = dict.immutableClone();
}
return gremlins;
}
public static String convertGremlins(String value) {
if (value == null)
return null;
String key, result = value;
Enumeration<String> enumeration = gremlins().keyEnumerator();
while (enumeration.hasMoreElements()) {
key = enumeration.nextElement();
result = ERXStringUtilities.replaceStringByStringInString(key,
gremlins().objectForKey(key), result);
}
return result;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden