1

我需要在获取 NSDictionary 中的键和值对的字符串中隐藏换行符。我将字符串作为值放在 NSDictionary 中。但我的问题是,当我运行我的应用程序时,它在我定义的标签或按钮中显示“\n”。我使用项目中 plist 中定义的键更改了所有字符串(硬编码)。

即:在我的plist中:

key: toOtherBank
value: Send it to \n the other bank account

在我的代码中:

[dictPayment setObject:[NSMutableArray array] forKey:[classUsed getValue: @"toOtherBank"]];

你能帮我隐藏字符串中的这个新行吗?

4

2 回答 2

2

为了删除换行符,只需在字符串上执行此操作:

[[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@""];

或者更简单:

[myString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
于 2013-07-25T08:06:12.070 回答
1

为了实现这一点,您只需要先删除换行符,您可以这样做......</p>

NSString *keyString = [UtilityFunctions getValue: @"toOtherBank"];
[keyString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
[dictPayment setObject:[NSMutableArray array] forKey:keyString];
于 2013-07-25T08:41:32.467 回答