How can I limit the length of a NSString? I would like to keep it below to equal to 100 characters/
NSUIntegerMax is 2^32 - 1 and NSString can hold a little over 4.2 billion characters.
string-truncate.swift Truncates the string to the specified length number of characters and appends an optional trailing string if longer. - Parameter trailing: A 'String' that will be appended after the truncation. - Returns: 'String' object. let str = "I might be just a little bit too long".
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
Here is the sample of fundamental manipulate string size.
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"
Hope, I understood right from your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With