views:

353

answers:

3

I know how to replace text in a string. But that's using keyboard (ASCII) characters. In Objective C, how do I indicate a degree symbol? Also, how do I get the ASCII code for a character?

+3  A: 

The degree symbol is Option-Shift-8 => °. I believe you can also do: @"\u00B0".

To get the ASCII code for a character, just get the character into a char and cast the char to an int.

Dave DeLong
Thanks, that was a superfast response. This also yields a degree symbol: @"\xC2\xB0" .
Scott Pendleton
That should be shift-option-8. The symbol you gave is a somewhat similar but unrelated small superscript circle that isn't used in English.
Chuck
@Chuck huh, I never knew about shift-opt-8. I believe that opt-0 is technically the male ordinal, but it looked close enough for me. :) Editing answer.
Dave DeLong
Actually, how the "male ordinal" symbol looks depends on the font. On some systems, it looks a lot like a degree symbol. On others (such as the one I'm on now), it has a line underneath.
Chuck
A: 

Option shift 8 also gives a similar character. It's the one I always use and I'm not sure of the difference between the two, except the SO font option 0 has a line under it.

Option+Shift+8 = °
Option+0 = º

David Kanarek
+1  A: 

To find characters not on your keyboard, select "Special Characters…" on the Edit menu.

To find ASCII values, look on http://www.asciitable.com/

Jon Reid
♭♭♭♭ here is the symbol for a flatted note in music. Would I need to use a specific font in order to get that symbol? And how would I know what escape sequence to use?
Scott Pendleton
@Scott use the Special Characters palette to find the letter. The tooltip (hover your mouse over the char) has the "Unicode:" info, which is your escape sequence (prefixed by `\u`.
Dave DeLong
Sweet! Thank you.
Scott Pendleton