简体   繁体   English

将字符串分割成字典

[英]Split string into dictionary

I have string like this "0 0.014E5" and I need it split into a Dictionary (in c#). 我有这样的字符串“ 0 0.014E5”,我需要将其拆分成一个Dictionary(在C#中)。 Where the firs zero will be the key and the number in exp format will be the value. 第一个零是键,而exp格式的数字将是值。

In Python: 在Python中:

s = "0 0.014E5".split(' ')
d = {}
d[s[0]] = s[1] 
# alternatively you can use:
d[s[0]] = float(s[1])

In Java: 在Java中:

String[] s = "0 0.014E5".split(" ");
Map<String, double> d = new HashMap<String, double>();
d.put(s[0], Double.parseDouble(s[1]));

In C#: 在C#中:

string[] s = "0 0.014E5".Split(' ');
var d = new Dictionary<string, string>();
d.Add(s[0], s[1]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM