여기에 텍스트 파일을 열고 파싱해야하는 코드가 있습니다.C# 루프가 증가하지 않음
그것은이 탭으로 해석되며, 줄 바꿈
최대한 멀리 볼 수 있듯이, 이는 2 차원 배열의 해석 데이터를 저장한다.
배열 [라인 데이터]
정도로
System.IO.FileInfo enemyFile = new System.IO.FileInfo("Data\\enemies.txt");
System.IO.StreamReader enemies = enemyFile.OpenText();
string line;
string[,] enemyInfo = new string[20,20]; // Array to store parsed text
while ((line = enemies.ReadLine()) != null)
{
string[] items = line.Split('\n');
string[] newItems;
for (int i = 0; i < items.Length; i++)
{
Console.WriteLine(i);
newItems = items[i].Split('\t');
for (int i2 = 0; i2 < newItems.Length; i2++)
{
enemyInfo[i, i2] = newItems[i2];
//testArray.ListArray(newItems);
Console.WriteLine("[{0},{1}] = {2}", i, i2, enemyInfo[i, i2]);
Console.ReadLine();
}
Console.WriteLine("-");
}
는 enemyInfo에 첫 번째 행에서 enemyInfo [0,0]와 다음의 파싱 된 데이터에 첫 행부터 제 파싱 된 데이터를 배치해야 [0,1] 등등.
줄 바꿈이 발생하면 enemyInfo [1,0]에 데이터를 저장 한 다음 enemyInfo [1,1] 등으로 데이터를 저장해야합니다.
Enemies.txt
Name of Race Race_ID Class_ID Sex_ID ToHit Evade Damage Strength Dexterity Constitution Intelligence Charisma Wisdom Experience Level Goblin 0 0 2 0 1 -1 6 8 6 4 4 4 1 1 Kobold 1 0 2 1 1 0 8 8 8 6 4 4 3 2
뭔가 잘못했을 나를 그냥인가? 내가 무엇을 시도하든 관계없이 첫 번째 for 루프에서 i를 증가시키지 않으므로 새 행을 배열의 동일한 차원에 계속 저장합니다.
희망 정보가 충분합니다.
미리 감사드립니다.
// 로니 헨릭슨
편집 :
내가 얻을 출력의 예를 추가 잊으.
[0,0] = Name of race
[0,1] = Race
and so on up to [0,14] and then it does this:
[0,0] = Goblin
[0,1] = 0
and so on, up to [0,14] and then it does the same with the next line (kobold).
얻을 문자열에'분할 ('\ n')를 '호출 직접이 줄을 분할한다 'ReadLine()'은 입력에서'\ n '에 도달하자마자 멈추기 때문에 항상 한 항목 (문자열 자체)의 배열을 반환합니다. – dasblinkenlight