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
+1
A:
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
Carl Norum
2010-03-03 04:28:12
or you could have whatever method that builds the string check the length :)
willcodejavaforfood
2010-03-03 08:53:57