OC截取字符串相关

2020-10-23  本文已影响0人  CoderZb

(1)截取某个字符串的前几位

NSString *originalStr = @"CoderZb";
NSString *finalStr = [originalStr substringFromIndex:3];
NSLog(@"最终的字符串为%@",finalStr);

(2)截取某个字符串的后几位

NSString *originalStr = @"CoderZb";
NSString *finalStr = [originalStr substringFromIndex:originalStr.length - 2];
NSLog(@"最终的字符串为%@",finalStr);

(2)截取某个字符串的任意位置

NSString *originalStr = @"CoderZb";
NSString *finalStr = [originalStr substringWithRange:NSMakeRange(1,3)];
NSLog(@"最终的字符串为%@",finalStr);
上一篇下一篇

猜你喜欢

热点阅读