NSString's Substring Crash Course
NSString * s1 = @"abc1234"; NSLog(@"s1 = %@",s1); NSLog(@"substringFromIndex,4 : %@",[s1 substringFromIndex:4]); NSLog(@"substringToIndex,4 : %@",[s1 substringToIndex:4]); NSLog(@"substringWithRange,NSMakeRange,2,4 : %@",[s1 substringWithRange:NSMakeRange(2, 4)]); NSRange indexOfString = [s1 rangeOfString:@"bc"]; NSLog(@"substringFromIndex,indexOfString,bc : %@",[s1 substringFromIndex:indexOfString.location]);
Will Produce the following output:
s1 = abc1234 substringFromIndex,4 : 234 substringToIndex,4 : abc1 substringWithRange,NSMakeRange,2,4 : c123 substringFromIndex,indexOfString,bc : bc1234
Comments
Post a Comment