Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > how to hard code a @"é"?

how to hard code a @"é"?
Thread Tools
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Sep 27, 2003, 11:26 PM
 
I'm trying to translate HTML escape codes like é back to text, like é. First of all, is there an easy way to do this?

if not, it would be easy enough to hard-code each number to be replaced by a certain one-char NSString, except it doesn't work. at all. I have an array of things like @"é", and when I see é, I replace it with [array objectAtIndex:233], and it's picking the right one, but the string I get is @"√©". Even this gives the same thing: NSString *string = @"é".

I tried entering a é in a text field and seeing what the character was. It was either -23 or 351. Making a character from those ints and then a string from the character gives È. I see no connection, and I'm giving up and pleading for assistance. Surely there must be an easier way to either hard code non-American characters or to skip it all and get HTML translation for free.

Anyone know?
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Sep 28, 2003, 12:52 AM
 
hum. I found a hackity hack hack way to do it. write the full escape code as the sole object in an array to a file. open the file as a string and delete the "amp;" from the now escaped & which has become &. then open the file as an array again and read the string, and the xml parser in NSArray has done your work for you. Of course, if this was for any other purpose than reading HTML (or XML), like say, you actually wanted to hard code a word with an accented e, cocoa still sucks. someone prove me wrong, kids
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Sep 28, 2003, 06:03 AM
 
Like it or not, the @"" syntax only allows you to put in 7-bit ascii characters. 8-bit characters, like é, differ depending on the encoding. I don't have any tables handy, so I'm not sure in what encoding é becomes 233. I did find out that it's \x00\xe9 in unicode, so then you can use something like this:
Code:
NSString *theString = [NSString stringWithCharacters:(unichar*)"\x00\xe9" length:1];
Works great. Just remember that, unlike @"" constants this string is auto released. If you're putting the string in an NSArray that shouldn't be something to worry about though.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 28, 2003, 09:35 AM
 
There's some code for this in OmniFoundation.
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Feb 29, 2004, 10:31 PM
 
sorry to drag up this old thread again, but I've come across a solution:

NSString *string = [NSString stringWithUTF8String:"é"];

I only looked this up again because I discovered a certain website is sending their page with the 8-bit chars included instead of HTML-escaped, and [NSString stringWithContentsOfURL] doesn't seem to like that. Anyway, hope this helps someone who doesn't feel like looking up hex codes for things.

PS: I once had a © in my source code for a similar reason and one day I noticed that it wasn't working, and it turned out Project Builder had choked on that character and changed it in the source file to some other random (yes I know it's not really random) crap. Anyway, now it's a "\251" instead, but keep a lookout for that.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:12 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2