Re: Translating accented characters to HTML entity equivalents
Re: Translating accented characters to HTML entity equivalents
- Subject: Re: Translating accented characters to HTML entity equivalents
- From: email@hidden
- Date: Thu, 13 Mar 2003 22:33:58 +0100
On jeudi, mars 13, 2003, at 08:53 PM, Phillip Ulrich wrote:
I have a need to convert accented characters (such as A) to their HTML
entity equivalents (Á) in an NSString. I am at a loss as to
how to do this.
The reason: I need to send the HTML entity equivalents instead of the
characters so that they get sent correctly through the web services
methods.
The problem: When I convert ordinary entities - such as < into < -
it works just fine. When I try to convert, say, A to Á it
doesn't work - it sends it as the accented character, and it gets
mangled and delivered incorrectly on the endpoint of the webservice.
I've tried converting it to a double-encoded entity - e.g., sending it
as &acute; - which, according to NSLog, is how WebServicesCore
actually sends < - but it makes no difference at all.
Note that if I type Á into a text field and send it that way,
it works great - it gets translated into &Aacute; and works fine
on the other end - it's only when I try to change A behind the scenes
that it fails to work.
The current code: Inefficient, I know. We have an NSString, theText.
NSArray *tmpArray = [theText componentsSeparatedByString:@"A"];
theText = [tmpArray componentsJoinedByString:@"Á"];
Any ideas?
Yes and no.
AFAIK, the reason why it's not working is that characters with accent
are not in the low ASCII table.
One solution could to use a NSLocalizable.strings file and do this
NSLocalizable.strings:
"a acute"="a`"; just imagine it's a a with acute accent
NSArray *tmpArray = [theText
componentsSeparatedByString:NSLocalizedString(@"a acute",@"Description
forthcoming")];
theText = [tmpArray componentsJoinedByString:@"Á"];
But this is not a really great solution indeed.
Other problem involves order of priority where you need to convert
first the &,<,> and other chars before working on the accented
characters.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.