• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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("&#160;", Character.toString((char)194) + Character.toString((char)160)); // non-breaking space
dict.setObjectForKey("&#174;", Character.toString((char)194) + Character.toString((char)174)); // registered trademark
dict.setObjectForKey("&#188;", Character.toString((char)194) + Character.toString((char)188)); // 1/4
dict.setObjectForKey("&#189;", Character.toString((char)194) + Character.toString((char)189)); // 1/2
dict.setObjectForKey("&#190;", Character.toString((char)194) + Character.toString((char)190)); // 3/4
dict.setObjectForKey("&#8211;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)147)); // endash
dict.setObjectForKey("&#8211;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)148)); // emdash
dict.setObjectForKey("&#8216;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)152)); // left single quotation mark
dict.setObjectForKey("&#8217;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)153)); // right single quotation mark
dict.setObjectForKey("&#8220;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)156)); // left double quotation mark
dict.setObjectForKey("&#8221;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)157)); // right double quotation mark
dict.setObjectForKey("&#8226;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)162)); // bullet
dict.setObjectForKey("&#8230;", Character.toString((char)226) + Character.toString((char)128) + Character.toString((char)166)); // ellipsis
dict.setObjectForKey("&#8482;", Character.toString((char)226) + Character.toString((char)132) + Character.toString((char)162)); // trademark


// serialized versions
dict.setObjectForKey("&#160;", "\\U00c2\\U00a0"); // non-breaking space
dict.setObjectForKey("&#174;", "\\U00c2\\U00ae"); // registered trademark
dict.setObjectForKey("&#188;", "\\U00c2\\U00bc"); // 1/4
dict.setObjectForKey("&#189;", "\\U00c2\\U00bd"); // 1/2
dict.setObjectForKey("&#190;", "\\U00c2\\U00be"); // 3/4
dict.setObjectForKey("&#8211;", "\\U00e2\\U0080\\U0093"); // endash
dict.setObjectForKey("&#8211;", "\\U00e2\\U0080\\U0094"); // emdash
dict.setObjectForKey("&#8216;", "\\U00e2\\U0080\\U0098"); // left single quotation mark
dict.setObjectForKey("&#8217;", "\\U00e2\\U0080\\U0099"); // right single quotation mark
dict.setObjectForKey("&#8220;", "\\U00e2\\U0080\\U009c"); // left double quotation mark
dict.setObjectForKey("&#8221;", "\\U00e2\\U0080\\U009d"); // right double quotation mark
dict.setObjectForKey("&#8226;", "\\U00e2\\U0080\\U00a2"); // bullet
dict.setObjectForKey("&#8230;", "\\U00e2\\U0080\\U00a6"); // ellipsis
dict.setObjectForKey("&#8482;", "\\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


  • Follow-Ups:
    • Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
      • From: Amedeo Mantica <email@hidden>
References: 
 >Stripping Microsoft Word bad characters ( some dashes and quotes ) (From: Amedeo Mantica <email@hidden>)
 >[SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes ) (From: Amedeo Mantica <email@hidden>)

  • Prev by Date: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
  • Next by Date: Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
  • Previous by thread: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
  • Next by thread: Re: [SOLVED] Re: Stripping Microsoft Word bad characters ( some dashes and quotes )
  • Index(es):
    • Date
    • Thread