/--------操作字符串--NSString(静态字符串)---------------------
NSString
*Beijing= @"北京欢迎您"; //字符串的声明
NSString
*log=@"北京欢迎您a"; //[NSString stringWithFormat:@"I am '%@'",Beijing]; //字符串格式化
NSString
*zhui = [Beijing stringByAppendingString:@"哈哈哈"]; //字符串追加
bool
b=[Beijing isEqualToString:log]; //字符串比较
NSString
*hh = @"http://www.sina.com.cn";
if([hh
hasPrefix:@"http"]){ //查找以http开头的字符串
NSLog(@"含有http");
}else{
NSLog(@"没有http");
}
NSString
*ss = @"123";
int
a = [ss intValue]+13; //字符串转int型
double
dd = [ss doubleValue]+33.3; //字符串转double型
NSLog(@"%g",dd);
//字符串转数组
NSString
*zifuchuan =@"one,two,three,four";
NSLog(@"string:%@",zifuchuan);
NSArray
*array = [zifuchuan componentsSeparatedByString:@","];
// NSLog(@"array:%@",array); //输出整个数组中所有元素
NSString
*value = [array objectAtIndex:0]; |