views:

2640

answers:

3

I feel incredibly stupid for asking this, but the documentation and Google are giving me no love at all.

I have a Unicode character I want to insert into a string literal in the source code of my iPhone app. I know its hex value. What is the proper escape sequence to use? And for that matter, what obvious source of information am I overlooking that would have told me this?

A: 

The proper escape sequence would be something along the lines of

wchar_t * str = L"\x0627";

See this question: http://stackoverflow.com/questions/755741/character-constant-000-xhh/755763

Edit: Oh, sorry, I missed the iPhone and Objective-C tags. The above is valid for generic C/C++, but I have not worked with iPhone development so your mileage may vary.

Christoffer
+8  A: 

Example:

 NSString *stuff = @"The Greek letter Beta looks like this: \u03b2"
Alex
That did it. Thanks!
Brent Royal-Gordon
You don't need to escape it. By default the editor and compiler toolchain will interpret the source code file as UTF8. You can use any unicode character in your string constants. This wasn't true previous to the Mac OS X 10.5 toolchain.
Ken
+2  A: 

If you don't want to put it directly in your string you can use a format specifier like this:

[string stringByAppendingFormat:@"%C", 0x2665];
Marc Charbonneau