Linq提供很方便的方法
可以將string split成dictionary
方法如下:
[VB.net]
[C#]
可以將string split成dictionary
方法如下:
[VB.net]
Dim Str As string="Allen$20,Betty$16"
Dim v As Dictionary(Of String, Integer) = Str.Split(",").Select(Function(s) s.Split("$")).ToDictionary(Function(i) i(0), Function(i) Integer.Parse(i(1)))
[C#]
String Str ="Allen$20,Betty$16"
Dictionary<string, int> v =
Str.Split(",")
.Select(s => s.Split("="))
.ToDictionary(i => i[0], i => Integer.Parse(i[1]))
留言