IOS -- NSString语法

 
NSString 三个提取子创的方法:
– substringFromIndex:
– substringWithRange:
– substringToIndex:
 
 
NSString与int和float的相互转换

  NSString *tempA = @"123";

  NSString *tempB = @"456";

 

1 字符串拼接

 NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];

 

2 字符转int

int intString = [newString intValue];

 

3 int转字符

NSString *stringInt = [NSString stringWithFormat:@"%d",intString];

 

4 字符转float

 float floatString = [newString floatValue];

 

5 float转字符

NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];

 

6 字符串连接

NSString* string; // 结果字符串

NSString* string1, string2; //已存在的字符串

string = [NSString initWithFormat:@"%@,%@", string1, string2 ];
string = [string1 stringByAppendingString:string2];</p>
string = [string stringByAppendingFormat:@"%@,%@",string1, string2];

 

7 NSMutableString,类似java 的 StringBuffer

posted @ 2016-12-28 10:31  Jager  阅读(133)  评论(0编辑  收藏  举报