OC中字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等

stringByTrimmingCharactersInSet:

注释:Returns a new string made by removing from both ends of thereceiver characters contained in a given characterset.


whitespaceAndNewlineCharacterSet

注释:Returns a character set containing only the whitespace charactersspace (U+0020) and tab (U+0009) and the newline and nextlinecharacters (U+000A–U+000D, U+0085).

另外可以用whitespaceCharacterSet替换whitespaceAndNewlineCharacterSet区别newlinenextline


whitespaceCharacterSet

注释:Returns a character set containing only the in-line whitespacecharacters space (U+0020) and tab (U+0009).

// 字符串除去空格后 字符串的个数

NSString *temptext = [messageTextField.textstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];

NSString *text = [temptextstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet ]];

注释:第1行是去除2端的空格  ,第2行是去除回车

// 限制输出空格

NSCharacterSet *whitespaceSet = [NSCharacterSetwhitespaceCharacterSet];

if([currentStringrangeOfCharacterFromSet:whitespaceSet].location != NSNotFound){

returnNO;

}

PS: 希望小二提供的有所帮助,欢迎留言。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Level I 隔段时间,便失去联络.好像人间蒸发般,遍寻不着. 其实若是敲门,他定是在家,沉溺于自己的世界.只不...
    五花王阅读 419评论 0 3
  • 苏宁易购418购物狂欢节的热度刚刚消退,声势更旺的五一大促便要来临。据悉,此次活动中苏宁易购将再放大招,大手笔投入...
    娱乐泛观察阅读 241评论 0 0
  • MIME格式详细介绍(转载) 1.Q什么是MIME?什么是MIME邮件? 2.常用MIME类型。 3.QConte...
    reflex阅读 5,251评论 0 2
  • 概述 Pilon骨折为发生于胫骨远端并累及关节面,由垂直暴力合并或不合并扭转暴力导致的骨折,常表现为干骺端的压缩和...
    云中瑞麟阅读 3,921评论 0 0