【发布时间】:2012-05-10 13:14:59
【问题描述】:
我有这样的字符串“0 0.014E5”,我需要将它拆分为字典(在 c# 中)。其中第一个零是键,exp 格式的数字是值。
【问题讨论】:
-
很棒的问题。关键是告诉大家你想要什么语言......
-
好的,在我的答案中添加了一个 C# 代码 sn-p。
标签: c# string dictionary split
我有这样的字符串“0 0.014E5”,我需要将它拆分为字典(在 c# 中)。其中第一个零是键,exp 格式的数字是值。
【问题讨论】:
标签: c# string dictionary split
在 Python 中:
s = "0 0.014E5".split(' ')
d = {}
d[s[0]] = s[1]
# alternatively you can use:
d[s[0]] = float(s[1])
在 Java 中:
String[] s = "0 0.014E5".split(" ");
Map<String, double> d = new HashMap<String, double>();
d.put(s[0], Double.parseDouble(s[1]));
在 C# 中:
string[] s = "0 0.014E5".Split(' ');
var d = new Dictionary<string, string>();
d.Add(s[0], s[1]);
【讨论】: