Answers:
首先,您必须确保该字符串至少包含3个字符:
NSString *fullString = /* obtain from somewhere */;
NSString *prefix = nil;
if ([fullString length] >= 3)
prefix = [fullString substringToIndex:3];
else
prefix = fullString;
substringToIndex:
如果您提供的索引超出字符串的末尾,将引发异常。