NSCharacterSet 去除NSString中的空格
转自: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中的空格的更多相关文章
- IOS NSCharacterSet 去除NSString中的空格
去除 username中的空格,table newline,nextline 代码如下: NSCharacterSet *whitespace = [NSCharacterSet whitespac ...
- NSCharacterSet去除字符串中的空格、删除指定\任意字符集
一.去除首尾的空格 /** 1.去除首尾的空格*/ NSString *strMsg=@" 简书作者:CoderZb "; NSString *strResult = [strMs ...
- php如何清除html格式并去除文字中的空格然后截取文字
PHP如何清除html格式并去除文字中的空格然后截取文字,详细分享一下处理方法(顺便对PHP清除HTML字符串的函数做了一个小结): htmlspecialchars 将特殊字元转成 HTML格式语法 ...
- Linux shell去除字符串中所有空格
Linux shell去除字符串中所有空格 echo $VAR | sed 's/ //g'
- 【代码笔记】iOS-去掉NSString中的空格
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ...
- java 去html标签,去除字符串中的空格,回车,换行符,制表符
public static String getonerow(String allLine,String myfind) { Pattern ...
- 通过apache,和nginx模块去除html中的空格和tab
最近一个项目中,合作方要求去除html中的空格,不想改代码,所以百度了一下通过apache,和nginx模块去除html中的空格和tab的方案,下面记录下来: 一.nginx nginx可以通过mod ...
- Python去除文件中的空格、Tab键和回车
def stripFile(oldFile, newFile): '''remove the space or Tab or enter in a file, and output a new fil ...
- Python编写“去除字符串中所有空格”
#利用迭代操作,实现一个trim()函数,去除字符串中所有空格 def trim(str): newstr = '' for ch in str: #遍历每一个字符串 if ch!=' ': news ...
随机推荐
- material design动画
这是一篇material design 文档动画部分的学习! Summary: Material Design动画交互 动画速度的3个原则 3种交互方式 如何设计有意义的动画 使人高兴的动画细节 1 ...
- 事件click,bind,click
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- linux如何修改登录用户密码
root登录后,passwd root可以修改root帐号的密码 其他具有sudo权限的用户登录后,sudo passwd root可以修改根帐号的密码 sudo passwd admin可以修改ad ...
- javascript 获取http头信息
Javascript中跟response header有关的就两个方法: getResponseHeader 从响应信息中获取指定的http头 语法 strValue = oXMLHttpReques ...
- screen space shadowmap unity
unity用到了screen space shadow map 1.camera 在light pos 生成depth1 2.screen space depth2 3.根据depth1 depth2 ...
- Java实现文件MD5加密
代码实现: import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.s ...
- Windows最常用的8个网络CMD命令总结
一,ping 它是用来检查网络是否通畅或者网络连接速度的命令.作为一个生活在网络上的管理员或者黑客来说,ping命令是第一个必须掌握的DOS命令,它所利用的原理是这样的:网络上的机器都有唯一确定的IP ...
- github下fork后如何同步源的新更新
当然,那是完全不用命令行的办法,其实我还是更推荐命令行,流程如下: 首先要先确定一下是否建立了主repo的远程源: git remote -v 如果里面只能看到你自己的两个源(fetch 和 push ...
- php 中 拓展 xdebug的完全理解
question: Xdebug unable to connect to client, where do I start debugging the debugger? I'm setting u ...
- 转: 加快Android编译速度
转: http://timeszoro.xyz/2015/11/25/%E5%8A%A0%E5%BF%ABandroid%E7%BC%96%E8%AF%91%E9%80%9F%E5%BA%A6/ 加快 ...