【问题标题】:Split string into dictionary将字符串拆分为字典
【发布时间】:2012-05-10 13:14:59
【问题描述】:

我有这样的字符串“0 0.014E5”,我需要将它拆分为字典(在 c# 中)。其中第一个零是键,exp 格式的数字是值。

【问题讨论】:

  • 很棒的问题。关键是告诉大家你想要什么语言......
  • 好的,在我的答案中添加了一个 C# 代码 sn-p。

标签: c# string dictionary split


【解决方案1】:

在 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]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    相关资源
    最近更新 更多