C#怎么样获取txt里面的数据信息

zhangzj155 2010-10-21 09:41:11
比如一个txt里面放的内容是
123 , 234
23 , 56

我想把txt里面的内容读取放入一个二维数组里面去
弄了好久没有弄出来
各位大虾
帮帮忙;
...全文
323 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
shixiujin 2010-10-21
  • 打赏
  • 举报
回复
学习了...
njw1028 2010-10-21
  • 打赏
  • 举报
回复
赶个末班车~
wuyq11 2010-10-21
  • 打赏
  • 举报
回复
foreach(string s in File.ReadAllLines(@"d:\a.txt"))
{
string[] arr=s.Split(',');
}

ysz89757 2010-10-21
  • 打赏
  • 举报
回复
StreamReader
Readline()
split(',')
zhengjianhua520 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhouzhangkui 的回复:]
C# code

using System;
using System.IO;
using System.Collections;

namespace TextFileReader_csharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class C……
[/Quote]


这个应该可以
fengduandeai 2010-10-21
  • 打赏
  • 举报
回复
数据流是对的
jshi123 2010-10-21
  • 打赏
  • 举报
回复
string[] lines = File.ReadAllLines(@"d:\test.txt");
int[][] array = lines.Select(l => l.Split(',').Select(s => int.Parse(s)).ToArray()).ToArray();
yxy10072510329 2010-10-21
  • 打赏
  • 举报
回复
string[] lineList=File.ReadAllLines("c:\\data.txt", Encoding.Default);
object[] array = new object[lineList.Length];
int i=0;
foreach (string line in lineList)
{
string[] elementList = line.Split(',');
array[i] = elementList;
i++;
}
string[][] arr = (string[][])array;
周药师 2010-10-21
  • 打赏
  • 举报
回复

using System;
using System.IO;
using System.Collections;

namespace TextFileReader_csharp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("c:\\test.txt");
string sLine="";
ArrayList arrText = new ArrayList();

while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();

foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
}
}
}
huwen7565833 2010-10-21
  • 打赏
  • 举报
回复
流读出,用逗号分隔!
龍月 2010-10-21
  • 打赏
  • 举报
回复
用StreamReader啊

Readline() //按行读取


用逗号分割
hanzhehanzhe 2010-10-21
  • 打赏
  • 举报
回复
读取所有的字符,用逗号分割,用回车的ascii码分割
linghubo 2010-10-21
  • 打赏
  • 举报
回复
string[] lineList=File.ReadAllLines("c:\\data.txt", Encoding.Default);
object[] array = new object[lineList.Length];
int i=0;
foreach (string line in lineList)
{
string[] elementList = line.Split(',');
array[i] = elementList;
i++;
}
string[][] arr = (string[][])array;
luozhongxian001 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yxy10072510329 的回复:]
C# code
string[] lineList=File.ReadAllLines("c:\\data.txt", Encoding.Default);
object[] array = new object[lineList.Length];
int i=0;
foreach (string line in li……
[/Quote]
这个可以1
haishenshizi 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yxy10072510329 的回复:]
UP
zhangzj155 2010-10-21
  • 打赏
  • 举报
回复
arr之前的元素都被覆盖了, 只有最后一行数据保存在arr中,
想要都保存怎么办 谢谢了
beautiful_melody 2010-10-21
  • 打赏
  • 举报
回复
动用StreamReader类读入到string对象中
利用string.split()函数进行以","的分割

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧