如何限制 NSString 的长度?我想将其保持在等于 100 个字符/
最佳答案
这是基本操作字符串大小的示例。
声明最大字符串长度:
int max = 5;
假设数组中有字符串列表:
NSArray *strs = [NSArray arrayWithObjects:@"My Little Puppy", @"Yorkerz", nil];
循环操作:
[strs enumerateObjectsUsingBlock:^(NSString *str, NSUInteger idx, BOOL *stop) {
if (str.length > max)
//get a modified string
str = [str substringToIndex:str.length-(str.length-max)];
NSLog(@"%@", str);
}];
结果:
"My Li" and "Yorke"
希望,我是从您的问题中理解的。
关于iphone - NSString 长度限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3544430/