1、定义一个NSCharacter(由于NSString中有全角符号和半角符号, 因此有些符号要包括全角和半角的)
NSCharacterSet *set=[NSCharacterSet characterSetWithCharactersInString:@"/@/:;()¥「」/"、[]{}#%-*+=_\\|~<>$€^•’@#$%^&*()_+’\""];
2、调用stringByTrimmingCharactersInSet
NSString*trimmedString=[string stringByTrimmingCharactersInSet:set];
3、去除两端的空格
NSString*temptext=[messageTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
4、去除两端的回车
NSString*text=[temptext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
网友评论