首页 > 代码库 > ios 字符串截取

ios 字符串截取

NSString *str = @"my name is jiemu";

1.从第三个字符开始,截取长度为4的字符串

NSString *str2 = [str substringWithRange:NSMakeRange(3,4)];//str2 = "name"

2.截取到第n为(第n位不算在内)

NSString *str3 = [str substringToIndex:2];//str3 = "my"

3.从第n为开始直到最后(包含第n位)

NSString *str4 = [str substringFromIndex:11];//str4 = "jiemu"

ios 字符串截取