Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

varsis

macrumors regular
Original poster
Nov 30, 2005
209
1
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

macrumors member
Jan 31, 2005
62
7
Sweden
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

Suspended
Nov 25, 2005
17,980
5,566
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.