将NSString转换为以特定字符分隔的NSDictionary [英] Convert NSString to NSDictionary separated by specific character
本文介绍了将NSString转换为以特定字符分隔的NSDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将此"5?8?519223cef9cee4df999436c5e8f3e96a?EVAL_TIME?60?2013-03-21"字符串转换为字典.以?"分隔
I need to convert this "5?8?519223cef9cee4df999436c5e8f3e96a?EVAL_TIME?60?2013-03-21" string into dictionary. Separated by "?"
字典就像
{
sometext1 = "5",
sometext2 = "8",
sometext3 = "519223cef9cee4df999436c5e8f3e96a",
sometext4 = "EVAL_TIME",
sometext5 = "60",
sometext6 = "2013-03-21"
}
谢谢.
推荐答案
将字符串拆分为较小的字符串并为其循环.这就是这种方式
Break the string to smaller strings and loop for them. This is the way
NSArray *objects = [inputString componentsSeparatedByString:@"?"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
int i = 1;
for (NSString *str in objects)
{
[dict setObject:str forKey:[NSString stringWithFormat:@"sometext%d", i++]];
}
这篇关于将NSString转换为以特定字符分隔的NSDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文