1 #import <Foundation/Foundation.h>
2
3 int main(int argc,const char *argv[])
4 {
5
6 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
7 //从文件获取字符串 编码、错误 参数
8 NSStringEncoding encoding = NSUTF8StringEncoding;
9 NSError *error = [[NSError alloc]init];
10
11 //定义初始化字符串1
12 NSString *str1 = @"wxiao";
13 //定义初始化字符串2
14 NSString *str2 = [NSString stringWithString:@"xiaow"];
15 //定义初始化字符串3
16 NSString *str3 = [[NSString alloc] initWithString:@"objc"];
17 //定义初始化字符串4
18 NSString *str4 = [NSString stringWithFormat:@"%@ and %@",str1,str3];
19
20 //定义初始化字符串5
21 NSString *str5 = [NSString stringWithContentsOfFile:@"test" encoding:encoding error:&error];
22
23 NSLog(@"%@",str1);
24 NSLog(@"%@",str2);
25 NSLog(@"%@",str3);
26 NSLog(@"%@",str4);
27 NSLog(@"%@",str5);
28
29 [pool drain];
30
31 return 0;
32 } |
|