[英]Set Limit and clear in nsmutableString
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. 我需要将可以附加到nsmutablestring的字符数限制为10。此外,我还需要在按下按钮时清除其内容。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.