请问怎么把多行文本中的每一行值用数组保存起来? 比如:文本有3行aabbcc我是打算用一个STRING数组的k[0]=aa,k[1]=bb,k[2]=cc,怎么写呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个用List会好一点,读一行存一行就行了 LIST我找了下资料,遇到个问题,比如我要读bb出来怎么写呢?list很不熟 你所说的文本是文本文件还是控件里的文本啊?文本文件里的内容可用StreamReader类StreamReader streamFile=new StreamReader();while (streamFile.Peek()>=0){str=streamFile.ReadLine();} using System.Collections; ArrayList arrList = new ArrayList(); arrList.Add("a"); arrList.Add("b"); arrList[1].ToString() //"b"或者用泛型也行List<T>,但是开始比较麻烦点,定义好了,使用起来比较方便 问题解决,方法如下: private void button5_Click(object sender, EventArgs e) { string[] kk = ReadTxt(Application.StartupPath + "\\update.ini"); label9.Text = kk[0]; label10.Text = kk[1]; } public string[] ReadTxt(string sPath)//读INI { string[] txt = new string[3]; StreamReader sr = new StreamReader(sPath, Encoding.GetEncoding("GB2312")); txt[0] =sr.ReadLine(); txt[1] =sr.ReadLine(); sr.Close(); return txt; } 如果不是3行,你的程序不是有问题?还是用List和循环较好 C#结构体数组初始化问题新方法 C# 子线程中timer失效的问题 小问题求大小神帮忙 怎样使DataGridView中的每行ComboBox的列表下拉内容不一样 关于异常处理 求救拉!!!!!! 请高手帮忙一下!!!!!!!!!!!!!在线等 奇怪了,显示的时间不正确呢?? 急 C#用DES加密解密 为什么dataset.table["bbb"]这种形式不让我用。 一点小问题,我没分了 C#为什么我的打印提示加载报表失败? 求一个存储数据的思路
文本文件里的内容可用StreamReader类
StreamReader streamFile=new StreamReader();
while (streamFile.Peek()>=0)
{
str=streamFile.ReadLine();
}
using System.Collections; ArrayList arrList = new ArrayList();
arrList.Add("a");
arrList.Add("b"); arrList[1].ToString() //"b"
或者用泛型也行List<T>,但是开始比较麻烦点,定义好了,使用起来比较方便
private void button5_Click(object sender, EventArgs e)
{
string[] kk = ReadTxt(Application.StartupPath + "\\update.ini");
label9.Text = kk[0];
label10.Text = kk[1];
}
public string[] ReadTxt(string sPath)//读INI
{
string[] txt = new string[3];
StreamReader sr = new StreamReader(sPath, Encoding.GetEncoding("GB2312"));
txt[0] =sr.ReadLine();
txt[1] =sr.ReadLine();
sr.Close();
return txt;
}