iOS NSString的api常用解析
1、创建常量字符串。
NSString *astring = @"This is a String!";
2、创建空字符串,给予赋值。
NSString *astring = [[NSString alloc] init]; astring = @"This is a 59wan.cn website!"; [astring release]; NSLog(@"astring:%@",astring); // NSString *astring = [[NSString alloc] init]; NSLog(@"0x%.8x", astring); astring=@"This is a String!"; NSLog(@"0x%.8x", astring); [astring release]; NSLog(@"astring:%@",astring);
3、在以上方法中,提升速度:initWithString方法
NSString *astring = [[NSString alloc] initWithString:@"This is a String!"]; NSLog(@"astring:%@",astring); [astring release];
4、用标准c创建字符串:initWithCString方法
*Cstring = ; NSString *astring = [[NSString alloc] initWithCString:Cstring]; NSLog(,astring); [astring release];
5、创建格式化字符串:占位符(由一个%加一个字符组成)
i = ; j = ; NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:,i,j]]; NSLog(,astring); [astring release];
6、创建临时字符串
NSString *astring; astring = [NSString stringWithCString:]; NSLog(,astring);
本文出自 “Cocos2D-X” 博客,请务必保留此出处http://lonag.blog.51cto.com/3340984/1630170
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。