删除来自保存在 NSString 中的 html 字符串
NSString* test = @"<b> Terms and Conditions</b><br />
- No smoking(by law) <br />
&nbsp; No chewing pan(by law)<br />"
[test stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@"s"];
我尝试删除该 " "
但失败了?有什么想法吗?
谢谢
NSString* test = @"<b> Terms and Conditions</b><br />
- No smoking(by law) <br />
No chewing pan(by law)<br />"
[test stringByReplacingOccurrencesOfString:@" " withString:@"s"];
I tried to remove that " "
but it fails to do so? Any ideas??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
test
是一个不可变的字符串,在进行替换时您会忽略结果。试试这个:test
is an immutable string and you are ignoring the result when you do the replacement. Try this:此方法不会更改您向其发送消息的字符串,而是返回一个新字符串。
This method doesn't change the string to which you send the message, but rather returns a new string.
我尝试使用以下单元测试来操作该字符串:
这会在我的 IDE 中通过。
我正在使用 OCUnit。
您是否将
[test stringByReplacingOccurrencesOfString...
放入新变量中?此方法不会改变对象,但返回一个新的字符串实例。
I tried to manipulate the string with the following unit test:
This passes in my IDE.
I'm using OCUnit.
Did you put the
[test stringByReplacingOccurrencesOfString...
in a new variable?This method does not mutate the object, but returns a new string instance.
您可能只是尝试替换 用 代替,看看它是如何编译的。
You might just try replacing with instead and see how that compiles that way.