background image

launch panel",@"greetings");

5,组合和提取字符串:
stringByAppendingString:
你可以合并字符串通过

initWithFormat:  、 stringWithFormat: 和 stringByAppendingFormat: 

你可以提取字符串

substringToIndex: , substringFromIndex:  和 substringWithRange: 方法。

你可以分隔字符串到子字符串数组,使用

 componentsSeparatedByString:

你也可以连接数组为一个字符串,使用

 componentsJoinedByString:

6,获得 C Strings:
要从一个字符串对象获得一个

C String,推荐使用 UTF8String。这返回一个 const char * 

using UTF8 string encoding。
const char *cString=[@"Hello,world" UTF8String];
返回的

C String 是一个临时对象,如果你想保留它,你需要创建一个 C buffer 并 copy 内容

到其中。
你也可以使用

initWithData:encoding: 和 dataUsingEncoding: 等方法来和 NSData 交互。

三、格式化字符串:
%@ 格 式 化 符 是 为 对 象 服 务 的 , 如 果 其 响 应 descriptionWithLocale: 消 息 , 否 则 他 发 送
description 消息。
%1.2f 表示格式化一个 double,带 2 个小数点。

NSNumber *number=@1234;
NSDictionary *dict=@{[NSDate data]:@"date"};

%C    表示 Unicode, 例如, NSString *s = [NSString stringWithFormat:@"Long %C dash", 
0x2014];
也可以使用
NSString *s=[NSString stringWithUTF8String:@"Long \xe2\x80\x94 dash"];

NSLog 和 NSLogv:

四、格式化符:
%@   descriptionWithLocale:   =>  description   , 也 工 作 于 CFTypeRef 对 象 , 返 回
CFCopyDescription 的结果。
%%  表示%字符
%d %D  表示 32 位   int
%u  %U  表示 32 位  unsigned int
%x  表示 32 位 unsigned int,并用 16 进制的形式表示 a-f 
%X 表示 32 位  unisigned int,并用 16 进制表示   A-F
%o %O  32 位 unsigned int ,8 进制表示
%f  表示 64 位 double
%e 64 位 double 使用科学计数法表示 ,e
%E  同上,E