1.字符串的创建(对象方法建立字符串)
NSString *s1 = @"hello";
NSString *s2= [ [ NSString alloc ] initWithString:@"jack" ];
NSString *s3= [ [ NSString alloc] initWithFormat:@"age is %d", 10 ] ;
NSString *s4 =[ [ NSString alloc ] initWithUTF8String:"jack" ];//C语言字符串---->OC字符串
(const) char *cs = [s4 UTF8String]; //OC字符串---->c语言字符串
{
NSString *s5 = [ [ NSString alloc ] initWithContentsOfFile:@"/Users/apple/Desktop/" encoding:NSUTF8StringEncoding error:nil];//读取文件中内容字符串
NSLog(@"\n%@",s5); //输出文件内容
}
|
|