1 #import <Foundation/Foundation.h>
2
3 int main (int argc,const char *argv[])
6 9
5
6 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
7//Get string encoding from file, error parameter
8 nsstringencoding encoding = nsutf8stringencoding;
9 Nserror *error = [[Nserror alloc]init];
10
11//define initialization string 1
NSString *str1 = @ "Wxiao";
13//define initialization string 2
NSString *STR2 = [NSString stringwithstring:@ "Xiaow"];
15//define initialization string 3
NSString *STR3 = [[NSString alloc] initwithstring:@ "OBJC"];
17//define initialization string 4
NSString *STR4 = [NSString stringwithformat:@ "%@ and%@", STR1,STR3];
19
20//define initialization string 5
NSString *STR5 = [nsstring stringwithcontentsoffile:@ "test" encoding:encoding error:&error];
22
NSLog (@ "%@", str1);
NSLog (@ "%@", str2);
NSLog (@ "%@", STR3);
NSLog (@ "%@", STR4);
NSLog (@ "%@", STR5);
28
[Pool drain];
30
return 0;
32}
Objective-c NSString Several ways to create initialization