【发布时间】:2011-04-15 07:09:56
【问题描述】:
我正在阅读一个字符串列表,每个字符串都可以包含多个占位符 (%@)。我想使用 stringWithFormat: 插入适当的值,但这仅适用于一次替换。我可以用什么来替换所有值?是否有某种字符串替换功能?
这是我正在尝试做的一个例子(一点点伪代码):
NSString[] patterns = { "my name is %@ every day", "my name is %@ and it will remain %@" };
foreach (NSString s in patterns )
{
// sometimes the string has one substitution, and sometimes
// more. The project where I am doing this throws a BAD_ACCESS
// error if more than one substitution is required so need
// to take a different approach?
print [NSString stringWithFormat:s, "Jack"];
}
【问题讨论】:
-
请贴出您目前拥有的代码。人们可以从那里提出建议。
-
+1 给黑蛙。你有数组或字典中的值吗?
-
我添加了一个例子来说明我想要做什么。