去除 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. Linux系统——http协议原理

    Web服务基础 用户访问网页基本流程 (1)在浏览器中输入域名,系统会查找系统本地的DNS缓存及hosts文件信息,查找是否存在域名对应的IP解析记录 (2)DNS解析域名为IP地址,系统会把浏览器的 ...

  2. cocos代码研究(20)Widget子类LoadingBar学习笔记

    理论基础 在一些操作中可视化指示进度条.显示给用户一个条表示操作已经完成了多少,继承自 Widget. 代码实践 static LoadingBar * create ()创建一个空的LoadingB ...

  3. python按行读取文件,如何去掉换行符"\n"

    for line in file.readlines(): line=line.strip('\n')

  4. centos设置代理上网

    centos设置代理上网   假设我们要设置代理为 IP:PORT 1.网页上网 网页上网设置代理很简单,在firefox浏览器下 Edit-->>Preferences-->> ...

  5. OpenCV在未知相机内参数情况下的立体图像矫正方法及注意事项

    http://blog.sina.com.cn/s/blog_4298002e01013yb8.html 很多时候我们不知道摄像机的内参数矩阵,并且我们也不太关注内参数到底是多少,因为我们仅仅关心如何 ...

  6. Windows Server 2008 R2 web服务器发布在线系统时遇到的问题

    1  HTTP 错误 404.2 - Not Found,由于 Web  服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面(如下图) 打开 Internet 信息服务(IIS) ...

  7. 20145315 《Java程序设计》第一周学习总结

    20145315 <Java程序设计>第一周学习总结 教材学习内容总结 第一章 java原来以橡树为名,后来才改成java,灵感是咖啡. 作者戏称JDK为java developer ki ...

  8. ubuntu18.04下搭建深度学习环境anaconda2+ cuda9.0+cudnn7.0.5+tensorflow1.7【原创】【学习笔记】

    PC:ubuntu18.04.i5.七彩虹GTX1060显卡.固态硬盘.机械硬盘 作者:庄泽彬(欢迎转载,请注明作者) 说明:记录在ubuntu18.04环境下搭建深度学习的环境,之前安装了cuda9 ...

  9. ERROR: cannot launch node of type [robot_pose_publisher/robot_pose_publisher]: robot_pose_publisher

    sudo apt-get install ros-indigo-robot-pose-publisher

  10. ng-grid

    请查看官网:http://angular-ui.github.io/ui-grid/ 简单的使用: 总的来说我们 1.需要引入ng-grid-1.3.2.js 2.在html页面需要加入  class ...