去除 username中的空格,table newline,nextline 
代码如下:

NSCharacterSet *whitespace = [NSCharacterSet  whitespaceAndNewlineCharacterSet];

NSString * string =@"liujun        \t          ";


string = [string  stringByTrimmingCharactersInSet:whitespace]; 

注释

stringByTrimmingCharactersInSet
Returns a new string made by removing from both ends of the receiver characters contained in a given character set.

whitespaceAndNewlineCharacterSet 
Returns a character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).

另外可以用 whitespaceCharacterSet 替换 whitespaceAndNewlineCharacterSet 区别newline nextline 
whitespaceCharacterSet 
Returns a character set containing only the in-line whitespace characters space (U+0020) and tab (U+0009).

NSString *content = @"    kahdahdah       \t           ";

NSString *temptext = [messageTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *text = [temptext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];

第1行是去除2端的空格

第2行是去除回车

NSCharacterSet的各个枚举类型的含义如下:

 1 controlCharacterSet//控制符
2 whitespaceCharacterSet
3 whitespaceAndNewlineCharacterSet//空格换行
4 decimalDigitCharacterSet//小数
5 letterCharacterSet//文字
6 lowercaseLetterCharacterSet//小写字母
7 uppercaseLetterCharacterSet//大写字母
8 nonBaseCharacterSet//非基础
9 alphanumericCharacterSet//字母数字
10 decomposableCharacterSet//可分解
11 illegalCharacterSet//非法
12 punctuationCharacterSet//标点
13 capitalizedLetterCharacterSet//大写
14 symbolCharacterSet//符号
15 newlineCharacterSet//换行符

IOS NSCharacterSet 去除NSString中的空格的更多相关文章

  1. NSCharacterSet 去除NSString中的空格

    转自:http://blog.sina.com.cn/s/blog_5421851501014xif.html 去除 username中的空格,table newline,nextline 代码如下: ...

  2. NSCharacterSet去除字符串中的空格、删除指定\任意字符集

    一.去除首尾的空格 /** 1.去除首尾的空格*/ NSString *strMsg=@" 简书作者:CoderZb "; NSString *strResult = [strMs ...

  3. php如何清除html格式并去除文字中的空格然后截取文字

    PHP如何清除html格式并去除文字中的空格然后截取文字,详细分享一下处理方法(顺便对PHP清除HTML字符串的函数做了一个小结): htmlspecialchars 将特殊字元转成 HTML格式语法 ...

  4. Linux shell去除字符串中所有空格

    Linux shell去除字符串中所有空格 echo $VAR | sed 's/ //g'

  5. 【代码笔记】iOS-去掉NSString中的空格

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ...

  6. java 去html标签,去除字符串中的空格,回车,换行符,制表符

    public static String getonerow(String allLine,String myfind)     {                           Pattern ...

  7. 通过apache,和nginx模块去除html中的空格和tab

    最近一个项目中,合作方要求去除html中的空格,不想改代码,所以百度了一下通过apache,和nginx模块去除html中的空格和tab的方案,下面记录下来: 一.nginx nginx可以通过mod ...

  8. Python去除文件中的空格、Tab键和回车

    def stripFile(oldFile, newFile): '''remove the space or Tab or enter in a file, and output a new fil ...

  9. Python编写“去除字符串中所有空格”

    #利用迭代操作,实现一个trim()函数,去除字符串中所有空格 def trim(str): newstr = '' for ch in str: #遍历每一个字符串 if ch!=' ': news ...

随机推荐

  1. hive表与外部表的区别

    相信很多用户都用过关系型数据库,我们可以在关系型数据库里面创建表(create table),这里要讨论的表和关系型数据库中的表在概念上很类似.我们可以用下面的语句在Hive里面创建一个表: hive ...

  2. java基础知识面试题(41-95)

    41.日期和时间:- 如何取得年月日.小时分钟秒?- 如何取得从1970年1月1日0时0分0秒到现在的毫秒数?- 如何取得某月的最后一天?- 如何格式化日期?答:问题1:创建java.util.Cal ...

  3. Ubuntu16.04 下创建新用户并赋予sudo权限

    https://blog.csdn.net/wales_2015/article/details/79643336

  4. cocos2dx 3.x 区域画图

    .h文件 bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent); void onTouchMoved(cocos2d::T ...

  5. 搭建Mybatis 出现 Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mapper.BatchCustomer.findBatchCustomerOneToOne

    Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection doe ...

  6. C++之路

    我学习C/C++也有两年了.开始是偏爱C语言和C++的语法特性强大,想用来做游戏开发.在深入学习的同时,逐渐了解到C++可以做很多事.大型项目需要用到运行效率高的C++,虽然运行效率越高,开发效率就要 ...

  7. Qt信号和槽连接方式的选择

    看了下Qt的帮助文档,发现connect函数最后还有一个缺省参数. connect函数原型是这样的: QMetaObject::Connection QObject::connect(const QO ...

  8. CEF3开发者系列之CefEnableHighDPISupport详解

    在CEF3中,CefEnableHighDPISupport()这个接口函数在使用时一般不为人所注意,但是如果稍有不慎,会造成打开的网页不能填满窗口的问题.如果是需要flash插件才能运行的游戏.则会 ...

  9. Python3基础 print 自带换行

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. 'workspace' in VS Code

    What is a 'workspace' in VS Code? You can save settings at the workspace level and you can open mult ...