【发布时间】:2017-11-16 10:49:26
【问题描述】:
我正在尝试从文件中读取并使用 c# 将其统一转换为字典。该文件包含类似的数据
1 1 1 acsbd
1 2 1 123ws
这里我想将前 6 个字符作为键和其余字符作为值。
这是我尝试过的代码(主要来自stackoverflow)
System.IO.StreamReader file = new System.IO.StreamReader (
@"D:\Programming\Projects\Launch pad\itnol\KeySound");
while ((line = file.ReadLine()) != null)
{
char[] line1 = line.ToCharArray();
if (line1.Length >= 11)
{
line1[5] = ':';
line = line1.ToString();
//Console.WriteLine(line);
}
var items = line.Split(new[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Split(new[] { ':' }));
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (var item in items)
{
Debug.Log(item[0]);
dict.Add(item[0], item[1]);
}
它符合但在运行时抛出IndexOutOfRangeException 异常
谢谢。
【问题讨论】:
-
好的。然后去做。有什么问题?
-
我想知道怎么做
-
你尝试了什么?你被困在哪里了?你读过How to Ask吗?
-
我编辑了问题,感谢您的帮助
标签: c# dictionary unity3d