iOS字符串

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 =@"sdfsfsfsAdfsdf";

NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组

NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf

NSString *str = array[1];

NSLog(@"str:%@",str);//结果是dfsdf

7、将string字符串转换为array数组

NSArray  *array = [str componentsSeparatedByString:@","];--分隔符

8、将array数组转换为string字符串

NSString *str = [array componentsJoinedByString:@","];--分隔符

你可能感兴趣的:(iOS字符串)