C#.net下文件操作,读文件区分符号。求教

matee 2009-04-21 12:36:13
读一个文件。
已知变量: char sign;//一个符号,比如 '*'.区分文件中信息。每行的 *之前为信息1, *后数据为信息2


要求读一个文本文件。
从开始操作文本文件,把每行中sign前的内容存储为string infoOne;sign后内容存储为string infoTwo;


直到读到文本结束。


求代码实现:
...全文
89 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝海D鱼 2009-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zsuswy 的回复:]
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace test
{
class Program
{
static void Main(string[] args)
{
StreamReader reader = new StreamReader(@"C:\filename.txt");
string sign = "*";
while (!reader.EndOfStream)
{
string strLine = rea…
[/Quote]
zsuswy 2009-04-22
  • 打赏
  • 举报
回复
根据你的具体需要,代码稍做修改即可。
zsuswy 2009-04-22
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace test
{
class Program
{
static void Main(string[] args)
{
StreamReader reader = new StreamReader(@"C:\filename.txt");
string sign = "*";
while (!reader.EndOfStream)
{
string strLine = reader.ReadLine();
string [] strs = strLine.Split(new string[] { sign },StringSplitOptions.None);
string infoOne = strs[0];
string infoTwo = strs[1];
}
}
}
}

111,126

社区成员

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

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

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