【发布时间】:2012-05-18 14:04:10
【问题描述】:
假设我有一个 NSString(或 NSMutableString)包含:
I said "Hello, world!".
He said "My name's not World."
最好的方法是:
I said \"Hello, world!\".\nHe said \"My name\'s not World.\"
我是否必须一遍又一遍地手动使用-replaceOccurrencesOfString:withString: 来转义字符,还是有更简单的方法?这些字符串可能包含来自其他字母/语言的字符。
这是如何在其他语言中使用其他字符串类完成的?
【问题讨论】:
-
我当然不会一遍又一遍地手动使用该方法。编写一个同时进行一系列替换的方法并不难。