• 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: Translating accented characters to HTML entity equivalents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translating accented characters to HTML entity equivalents


  • Subject: Re: Translating accented characters to HTML entity equivalents
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Thu, 13 Mar 2003 17:03:52 -0500

Have you tried something like this:

NSString *EncodeForHTML(NSString *input)
{
unsigned length = [input length];
unichar *buffer = malloc(length * sizeof *buffer);

if(buffer)
{

NSMutableString *result = [NSMutableString string];

for(unsigned i=0; i<length; ++i)
{
if(buffer[i] >= 'a' && buffer[i] <= 'z' ||
buffer[i] >= 'A' && buffer[i] <= 'Z' ||
buffer[i] >= '0' && buffer[i] <= '9')
{
[result appendFormat: @"%c", buffer[i]];
}
else
{
[result appendFormat: @"&#x%x;", buffer[i]];
}
}

free(buffer);
return result;
}

return nil;
}



On Thursday, March 13, 2003, at 11:53 AM, Phillip Ulrich wrote:

From: Phillip Ulrich <email@hidden>
Date: Thu Mar 13, 2003 11:53:03 AM US/Pacific
To: email@hidden
Cc: email@hidden
Subject: Translating accented characters to HTML entity equivalents

I have a need to convert accented characters (such as A) to their HTML entity equivalents (&Aacute;) 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 &lt; - it works just fine. When I try to convert, say, A to &Aacute; 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 &amp;acute; - which, according to NSLog, is how WebServicesCore actually sends &lt; - but it makes no difference at all.
Note that if I type &Aacute; into a text field and send it that way, it works great - it gets translated into &amp;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:@"&Aacute;"];

Any ideas?

--Phil Ulrich
_______________________________________________
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.


--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
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.

References: 
 >Re: Translating accented characters to HTML entity equivalents (From: Alex <email@hidden>)

  • Prev by Date: Re: Translating accented characters to HTML entity equivalents
  • Next by Date: is there a way to extract text from pdfs?
  • Previous by thread: Re: Translating accented characters to HTML entity equivalents
  • Next by thread: Re: Translating accented characters to HTML entity equivalents
  • Index(es):
    • Date
    • Thread