IOS String Common Processing Details
- 2021-10-27 09:22:51
- OfStack
IOS String Common Processing Details
NSString *tempA = @"123";
NSString *tempB = @"456";
1. String splicing
NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2. Character to int
int intString = [newString intValue];
3. int to characters
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
4. Character to float
float floatString = [newString floatValue];
5. float to characters
NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];
6. Intercept a string
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];// Intercept subscript 7 String after
NSLog(@" The truncated values are: %@",string);
[string substringFromIndex:2];// Intercept subscript 2 Previous string
NSLog(@" The truncated values are: %@",string);
7. Match String
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];// Subscript obtained by matching
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];// Intercept the String of Range Class
NSLog(@" The truncated values are: %@",string);
8. Separate strings
NSString*string =@"sdfsfsfsAdfsdf";
NSArray *array = [string componentsSeparatedByString:@"A"]; // Slave character A Divided into 2 An array of three elements
NSLog(@"array:%@",array); // The result is adfsfsfs And dfsdf
Thank you for reading, hope to help everyone, thank you for your support to this site!