搜索

C# 中文本文件处理方法

发布网友 发布时间:2022-04-20 08:37

我来回答

3个回答

热心网友 时间:2023-10-04 22:35

using System;
using System .Text ;
using System .IO ;
using System .Collections .Generic ;

namespace windly
{
class Program
{
public static void Main(string[] args)
{uu:
Console .WriteLine ("现在文本内容为:");
string hao=@"C:\123.txt";
StreamReader f=new StreamReader (hao ,System .Text .Encoding .Default );
string yan=f.ReadToEnd ();
string [] xy=yan .Split ();
int xx=1;

for(int i =0;i<=xy.Length-1 ;i++)
{

if(xy[i]=="")
{
}
else
{
if(xx<2)
{
xx=xx+1;
if(xx==1)
{
Console .Write (xy[i]+"\n");
}
else
{
Console .Write (xy[i]+" ");
}
}
else
{
xx=1;
Console .Write (xy[i]+" "+"\n");
}
}
}
Console .WriteLine ();
f.Close() ;
Console .WriteLine ("请选择1修改数据2增加数据");
int xyz =int.Parse (Console .ReadLine ());
if(xyz ==1)
{
Console .WriteLine ("请输放你想修改数据的名字");

string su=Console .ReadLine ();
int u3=1;
for (int i1=0;i1<=xy.Length -1;i1++)
{
if(xy[i1]==su)
{
Console .WriteLine ("请选择1.删除记录、2.更改数据");
int b1=int.Parse (Console .ReadLine ());

if(b1==1)
{
xy[i1]="";
for(int i0 =i1;i0<=xy .Length-1;i0++)
{
if( xy[i0]!="")
{
xy[i0]="";
}
break ;
}

StreamWriter dai=new StreamWriter (@"C:\123.txt",false,System .Text .Encoding.Default );

for(int s=0;s<=xy.Length -1;s++)
{
if(xy[s]==""|xy[s]==" ")
{
}
else
{
if(u3<3)
{
dai.Write(xy[s]+" ");
u3=u3 +1;
}
else
{
u3=2;
dai.WriteLine();
dai.Write(xy[s]+" ");
}

}
}
dai .Close ();
Console .WriteLine ("删除完成");

goto uu;
}
if(b1==2)
{
Console .WriteLine ("请输放{0,1}的数据:",su);
int ui=int.Parse (Console .ReadLine ());

for(int hh=0;hh<=xy.Length -1;hh++)
{
if(xy[hh]==su)
{
xy[hh+1]=ui.ToString ();

}
}
int u4=1;

StreamWriter de=new StreamWriter (@"C:\123.txt",false );
for(int s=0;s<=xy.Length -1;s++)
{
if(xy[s]==""|xy[s]==" ")
{
}
else
{
if(u4<3)
{
de.Write(xy[s]+" ");
u4=u4 +1;
}
else
{
u4=2;
de.WriteLine();
de.Write(xy[s]+" ");
}

}
}
de .Close ();
Console .WriteLine ("修改完成");

goto uu;
}

}
}
}
if(xyz ==2)
{
Console .WriteLine ("请输入你想要增加的名字和数据 中间有空格格开 例如abc 123");
string sppy=Console .ReadLine ();

StreamWriter nn=new StreamWriter(@"C:\123.txt",true,System .Text .Encoding .Default );
nn.WriteLine (sppy);
nn.Close ();
Console .WriteLine ("增加完成!^—^");
goto uu;
}
Console .ReadKey ();
}
}
}希望对你有所帮助吧。。。。。。。。不解释不解释

热心网友 时间:2023-10-04 22:35

重写进去吧。。。。比如删除你上面的jole,就是少写一行FileStream myFs = new FileStream(path,FillMode.Create);StreamWriter mySw= new StreamWriter(myFs);mySw.Write("jii 123"); mySw.Close();myFs.Close();

热心网友 时间:2023-10-04 22:36

readline writeline
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top