我需要在字符串末尾截断逗号,有点像这样:
NSString *string = @" this text has spaces before and after ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
而不是whitespaceCharacterSet有类似commaCharacterSet的东西吗?
答案 0 :(得分:3)
如果每个字符串在开头和结尾都有逗号/空格:
NSRange range = NSMakeRange(1, [string length-1]);
NSString *trimmedString = [string substringWithRange:range];
如果您只想修剪逗号:
[NSCharacterSet characterSetWithCharactersInString:@","];