PDA

View Full Version : NSString and Foreign characters




varsis
Jan 29, 2008, 02:27 AM
Hi,

I have a NSString which is formated using a stringWithFormat, but when I pass a foreign character in it goes weird.

Characters like ,

they mess it right up. Is I use NSLog, it will show the right character, but if you put this into an NSString it goes wonk.



Bakerman
Jan 29, 2008, 02:43 AM
Use [NSString stringWithUTF8String:"..... ....."]. Note the absence of the @ before the string, and make sure that the file encoding of your source file is UTF8.

Or use a strings file and the NSLocalizedString macro family.

gnasher729
Jan 29, 2008, 12:10 PM
Hi,

I have a NSString which is formated using a stringWithFormat, but when I pass a foreign character in it goes weird.

Characters like ,

they mess it right up. Is I use NSLog, it will show the right character, but if you put this into an NSString it goes wonk.

When you ask for programming help, remember that there are quite a few capable programmers here, but very very few good mind readers. How are we supposed to figure out what your problem is? As a good exercise for a beginner, what about a post where you describe exactly what you are doing. Like: What are you doing? What do you expect to happen? What happens?

You should check out the documentation. You should especially check the page with format specifiers, and you should know the difference between %c and %C, and the difference between %s, %S and %@. It would also be great if you would know what the difference between "string" and @"string" is.