Note: If the @ symbol before the quotes in @"The number at index %d is %@" looks a little strange, remember that Objective-C is the C language with a couple of extensions. One of the extensions is that strings are instances of the class NSString. In C, strings are simply pointers to a buffer of characters that ends in the null character. Both C strings and instances of NSString can be used in the same file. To differentiate between constant C strings and constant NSStrings, you must put @ before the opening quote of a constant NSString:
// C string
char *foo;
// NSString
NSString *bar;
foo = "this is a C string";
bar = @"this is an NSString";
You will use mostly NSString in Cocoa programming. Wherever a string is needed, the classes in the frameworks expect an NSString. However, if you already have a bunch of C functions that expect C strings, you will find yourself using char * frequently.
You can convert between C strings and NSStrings:
const char *foo = "Blah blah";
NSString *bar;
// Create an NSString from a C string
bar = [NSString stringWithUTF8String:foo];
// Create a C string from an NSString
foo = [bar UTF8String];
Because NSString can hold Unicode strings, you will need to deal with the multibyte characters correctly in your C strings, and this can be quite difficult and time consuming. (Besides the multibyte problem, you will have to wrestle with the fact that some languages read from right to left.) Whenever possible, you should use NSString instead of C strings.



