NSRegularExpression 删除空格
我需要一点关于 iPhone 上的正则表达式的启动。实际上我正在处理 UITextField.text。如果文本的值为空并且该值已经存在,我可以处理它。但是,如果该值只是空格,我不想使用它。因此,如果该值类似于“”或“文件夹”,我希望该值分别为“”和“文件夹”。
我计划使用 NSRegularExpression 删除空格并浏览文档。但这有点令人困惑。因此,帮助我解决从给定字符串中删除空格的问题。先感谢您。
I need a little kickstart on regex on the iPhone. Actually I am dealing with UITextField.text. If the value of the text is empty and if the value already exist, I can able to deal it. But, if the value is simply white spaces, I do not want to use it. So, if the value is like " " or " folder", I want the value to be "" and "folder" respectively.
I planned to use NSRegularExpression to remove the white space and went through the documents. But it was little confusing. So, help me to come out of the problem of removing white space from the given string. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:您需要修剪字符串,因此不需要正则表达式,只需使用:
Edit: you need to trim string, so no regular expression is needed, simply use:
正则表达式将是:
然后您将其替换为“”
您如何通过 iOS 语法进行替换我不知道,但这就是全部的正则表达式:)
The regexp would be:
You would then replace that with ""
How you do that through iOS syntax for the replacement I don't know, but that's the regExp for it all :)
一个更实际的问题是,如何修剪和压缩空白,
A more practical question is, How to trim and condense white-spaces,