 |
 |
how to hard code a @"é"?
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
There's some code for this in OmniFoundation.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|