I need to limit the number of characters that can be appended to an nsmutablestring to 10. Also i need to clear its contents on a button press. What is the best method to do that? pls help
You can write a category. Something like this:
@interface NSMutableString (append10)
-(void)appendString:(NSString *)aString;
@end
@implementation NSMutableString (append10)
-(void)appendString:(NSString *)aString
{
NSString *toAppend = aString;
if ([aString length] > 10)
{
// truncate string
}
[super appendString:toAppend];
}
@end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.