ios – 用Objective-C替换空格

栏目: Objective-C · 发布时间: 5年前

内容简介:我需要验证一个UITextField来替换一个空格””,并想知道这是怎么回事?翻译自:https://stackoverflow.com/questions/14387401/replace-blank-spaces-with-20-in-objective-c

我需要验证一个UITextField来替换一个空格””,并想知道这是怎么回事?

如果你只是想用另一个值替换字符串中的字符,请查看方法stringByReplacingOccurrencesOfString:withString:on NSString

.

返回一个新字符串,其中接收器中所有出现的目标字符串都被另一个给定字符串替换.

NSString *originalString = @"Sample text with spaces";

NSString *newString = [originalString stringByReplacingOccurancesOfString:@" " withString:@"%20"];

如果您尝试对URL进行编码,请在 NSString 上使用stringByAddingPercentEscapesUsingEncoding:

使用给定的编码返回接收器的表示,以确定将接收器转换为合法URL字符串所需的转义百分比.

NSString *originalString = @"Sample text with spaces";

NSString *newString = [originalString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

翻译自:https://stackoverflow.com/questions/14387401/replace-blank-spaces-with-20-in-objective-c


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Text Processing in Python

Text Processing in Python

David Mertz / Addison-Wesley Professional / 2003-6-12 / USD 54.99

Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing som......一起来看看 《Text Processing in Python》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具