Txt文件问题C# [英] Txt File Problem C#

查看:64
本文介绍了Txt文件问题C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整天都在努力,无法找到解决方案


for(int i = 0; i< NumberOfLines; i ++)

{

ID [i] = tr.ReadLine();

lines = ID [i] .Split(new Char [] {''''}};

comboBox1.Items.Add(lines [0]);

}

private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)

{

textBox1.Text = lines [1];

}


ok问题仅为行[1]读取数组的结尾,我总是得到最后的结果无论我怎么做尝试改变它,但行[0]工作正常???我怎么能让文本框只显示基于行[0]的正确的东西。

示例行[0] = 1

我怎样才能获得行[ 1]显示第一行。

行[0] = 2

我怎样才能得到行[1]来显示第二行等等。

解决方案

或者至少告诉我怎么做这个


string [,] threebythree = new string [Int16.Parse(ID [i]),Int16.Parse(lines [i])];

因为即使我得到了转换

错误:输入字符串的格式不正确。


不完全确定这里的目标是什么......但看起来如果你从列表框中选择第二项(迭代1,因为它是零索引)你想要第二行您的文件出现在文本框中。列表框中选择的第四个项目=文本框中的第四个项目。这是目标吗?


两者都是零索引的。所以从列表框中取出.SelectedIndex值并将其作为行号索引显示在文本框中。


如果我误解了你的目标并导致你走入歧途,我的最深的道歉。


sry我以一种令人困惑的方式说出来。


文本文件中有这个:

0 string1 5

1 string2 10

2 string3 15

行[0]为0,1,2

行[1]为string1,string2,string3

行[2]为5,10,15


ID [0]是0 string1 5

ID [1]是1 string2 10

ID [2}是2 string3 15


当我尝试将行[1]写入textbox1.text即可获得string3。

i不知道使其成为string1的代码然后是string2,然后是string3。

所以它的阅读最后一个数组。

i想让一个像(ID [i],lines [i])这样的数组成为可能,这就是我在回复中尝试做的,但当然不行

been working on this all day and cant figure out a solution

for (int i = 0; i < NumberOfLines; i++)
{
ID[i] = tr.ReadLine();
lines = ID[i].Split(new Char[] { '' '' });
comboBox1.Items.Add(lines[0]);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = lines[1];
}

ok problem is lines[1] only reads the end of the array and i allways get the last result no matter what i do to try to change it, but lines[0] works fine??? how can i get the textbox to only show the right thing based on what lines[0] is.
example lines[0] = 1
how can i get lines[1] to display the first line.
lines[0] = 2
how can i get lines[1] to display the 2nd line and so forth.

解决方案

or at least tell me how i can do this

string[,] threebythree = new string[Int16.Parse(ID[i]), Int16.Parse(lines[i])];
because even with the conversions i get
ERROR: Input string was not in a correct format.


Not exactly sure what the goal here is... But looks like if you pick the second item from a list box (iteration 1 since it is zero indexed) that you want the second line of your file to appear in a text box. Fourth item selected in the listbox = fourth item in the text box. Is that the goal?

Both are zero-indexed. So take the .SelectedIndex value from the listbox and use that as the line number index to show in the text box.

If I have mis-understood your goal and lead you astray, my deepest apologies.


sry i said it in a confusing way.

The text file has this in it:
0 string1 5
1 string2 10
2 string3 15

lines[0] is 0, 1, 2
lines[1] is string1, string2, string3
lines[2] is 5, 10, 15

ID[0] is 0 string1 5
ID[1] is 1 string2 10
ID[2} is 2 string3 15

when i try to write lines[1] to textbox1.text im getting string3 only.
i dont know the code to make it string1 first then string2, then string3.
so its reading the last array first.
i would like to make it possible to just have an array like (ID[i], lines[i]) thats what i tried doing in the reply but of course that doesnt work.


这篇关于Txt文件问题C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆