hiding newline in the string which gets key and value pair in NSDictionary
本问题已经有最佳答案,请猛点这里访问。
我需要在 NSDictionary 中获取键值对的字符串中隐藏换行符。我将字符串作为 NSDictionary 中的值。但我的问题是,当我运行我的应用程序时,它显示 " \\\\
" 在我定义的标签或按钮中。我更改了所有字符串 - 硬编码 - 使用在我的项目中的 plist 中定义的键。
即:在我的 plist 中:
1 2 3 | key: toOtherBank value: Send it to \ the other bank account |
并在我的代码中:
1 | [dictPayment setObject:[NSMutableArray array] forKey:[classUsed getValue: @"toOtherBank"]]; |
你能帮我隐藏字符串中的这个新行吗?
为了删除换行符,只需对字符串执行以下操作:
1 | [[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@""]; |
或者更简单:
1 2 | [myString stringByReplacingOccurrencesOfString:@"\ " withString:@""]; |
为了实现这一点,你只需要先删除换行符,你可以做 asa€|
1 2 3 | NSString *keyString = [UtilityFunctions getValue: @"toOtherBank"]; [keyString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; [dictPayment setObject:[NSMutableArray array] forKey:keyString]; |