7

我已经阅读了所有内容,但 \" 不起作用。

我正在尝试创建一个如下所示的字符串:

"SomeString" = "另一个字符串"

这是我必须插入双引号的代码:

NSString *newOutput = [NSString stringWithFormat:@"%@ \" = \" %@", output, [englishDic objectForKey:str]];

它输出的只是:

"RateThisAppDontAsk \" = \" Don't ask again"

我想也许是“=”引起了问题,但删除仍然给了我这样的输出:

"RateThisAppDontAsk \"  \" Don't ask again"

任何帮助将不胜感激!

4

3 回答 3

28

在一个小的 MacOS X 命令行测试程序中为我工作。这是所有代码:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSString *newOutput = [NSString stringWithFormat:@"%@ \" = \" %@", @"foo", @"bar"];
        NSLog(newOutput);
    }
    return 0;
}

输出是:

test[54844:403] foo " = " bar

如果你想在foobar之前加上引号,请添加:

NSString *newOutput = [NSString stringWithFormat:@"\"%@\" = \"%@\"", @"foo", @"bar"];

新输出是:

test[54873:403] "foo" = "bar"
于 2013-03-27T20:16:38.903 回答
4
 NSString *output = @"RateThisAppDontAsk";
 NSString *nextString = @"Don't ask again";

 NSString *newOutput = [NSString stringWithFormat:@"\"%@\" = \"%@\"", output, nextString];
 NSLog(@"%@",newOutput);

输出

"RateThisAppDontAsk" = "Don't ask again"
于 2013-03-27T20:18:15.347 回答
0

这是你需要做的

NSString *firstObject = @"RateThisAppDontAsk";
NSString *secondObject = @"Don't ask again";
NSString *newOutput = [NSString stringWithFormat:@"\"%@\" = \"%@\"",firstObject,secondObject];

输出

test[4556:c07] "RateThisAppDontAsk" = "Don't ask again"
于 2013-03-27T20:17:25.007 回答