转自: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. 如何使用Less?

    LESS是动态样式语言,赋予CSS动态语言的特性,如变量.继承.运算.函数,使得CSS更方便编写与维护.>>官网 less @color:#ff0000; body{color:@colo ...

  2. Unity3D手机游戏开发

    <Unity3D手机游戏开发> 基本信息 作者: 金玺曾 出版社:清华大学出版社 ISBN:9787302325550 上架时间:2013-8-7 出版日期:2013 年8月 开本:16开 ...

  3. Calico网络策略实践

    因为Kubernetes官方用的flannel无法实现多租户环境下的网络隔离,建立起来的pod之间实际可以相互访问,而Calico可以实现,因此周末找个时间试了一下大概的过程. 前面的kubernet ...

  4. FPGA作为从机与STM32进行SPI协议通信---Verilog实现

    一.SPI协议简要介绍 SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用 ...

  5. unity 显示mipmaplevel

    https://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html 显示mipmaplevel 需要贴图可读写不压缩 using Uni ...

  6. php中自定义事件---事件驱动

    PHP中自定义事件驱动,处理机制. 原文:https://www.cnblogs.com/mafeifan/p/4322271.html ------------------------------- ...

  7. DotNetBar ComboBoxEx

    DotNetBar ComboBoxEx using System; using System.ComponentModel; using System.Drawing; using System.R ...

  8. 搭建dubbo-admin-2.5.3

    dubbo管理界面 一,安装zookeeper 1,下载包zookeeper-3.3.3.tar.gz 2,解压 tar zxvf zookeeper-3.3.3.tar.gz cd zookeepe ...

  9. C#秘密武器之特性

    一.概述 Attribute说白了就是一个类而已,里边一般含有一些附加信息,或者一些特殊的处理逻辑,以便告诉编译器应用该特性的东东是个奇葩,需要特殊对待! 二.使用时的注意事项 2.1. Attrib ...

  10. JMeter 六:Listener

    参考:http://jmeter.apache.org/usermanual/listeners.html Listener是用来展示Sampler结果的元件. 结果可以被展示在树.表格.图表或者简单 ...