转自:http://blog.sina.com.cn/s/blog_5421851501014xif.html

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

NSCharacterSet *whitespace = [NSCharacterSet  whitespaceAndNewlineCharacterSet];

NSString * username = [mUsernameField  stringValue];

username = [username  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 *temptext = [messageTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *text = [temptext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];

第1行是去除2端的空格

第2行是去除回车

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

  1. IOS NSCharacterSet 去除NSString中的空格

    去除 username中的空格,table newline,nextline 代码如下: NSCharacterSet *whitespace = [NSCharacterSet  whitespac ...

  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. 嵌入式学习之Nand Flash

    转:http://m.blog.csdn.net/blog/woshixiongge/9017149 Nand Flash是flash存储器的一种,其内部采用非线性宏单元模式,为固态大容量内存的实现提 ...

  2. 一日一点RakNet(3)--介绍

    介绍 安装 请参考Compiler Setup页,有什么问题在这块有解答.如果有额外的问题参考FAQ,http://www.jenkinssoftware.com,或者邮件联系我们.高级用户可以直接跳 ...

  3. Eureka的自我保护机制

    最近项目在Kubernetes上使用Eureka遇到一些问题,在网站上找到一篇针对Eureka自我保护机制原理的文章,觉得不错,总结如下: Eureka的自我保护特性主要用于减少在网络分区或者不稳定状 ...

  4. tomcat+mysql在Kubernetes环境

    基于PV作为交换目录将应用最终拷贝入/tomcat/webapps目录 进入Docker后,修改/bin/catalina.sh,加入jdbc的类 \webapps\mytestsql\WEB-INF ...

  5. Firefox的缓存问题

    使用Firefox调试代码时,JS或CSS文件修改后,怎么刷新都不生效.原来是Firefox缓存的问题.但Firefox没有像IE一样有个每次读取最新的设置. 设置Firefox不缓存页面: 新建标签 ...

  6. Index 和 Type 的区别

    原文: Index vs. Type By Adrien Grand 译者: fengchang 对于 ES 的新用户来说,有一个常见的问题:要存储一批新的数据时,应该在已有 index 里新建一个 ...

  7. Java小案例-(逃离迷宫)

    Java小案例-(逃离迷宫) 一,迷宫需求描述: 1,用户输入迷宫图(限制方形):字母1位墙,0为通,e为出口,m为入口,*为已访问的位置,用外围1围住迷宫 2,运行轨迹右,左,下,上 3,判断该迷宫 ...

  8. NTP for Linux

    一.服务概述 NTP(network time  protocol 网络时间协议)服务器是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源做同步化,提供高精度的时间校正,在LAN上与 ...

  9. [Android Pro] Android的5个进程等级

    1.foreground process     正处于activity resume状态     正处于bound服务交互的状态     正处于服务在前台运行的状态(StartForeGround( ...

  10. PAAS云服务平台

    云计算是一种可以方便.按需从网络訪问的.可配置的.共享的资源池(如网络.server.存储.应用程序和服务)模型,且仅仅需最少的管理(服务提供方交互)就可以高速供应和公布该模型. 云计算平台的核心部分 ...