已经知道文本中第几行,想用streamwriter把这行删除掉 不知道如何实现可以说是把这行删除掉 不留空格 不留空行 完全删除掉。请教
解决方案 »
- 使用了system.timers.timer以后,如何让timer暂停?
- Do me a favor...
- c#怎么做这样的布局窗体winform
- 绑定数据到GridView时,GridView的标题是英文,怎么变为中文
- 用C#能不能做语音识别程序?
- visual C# 做win程序时怎样让窗体启动时在屏幕指定的位置??
- C#XML
- 网页之间传递数据,如何用request.querystring可以获得非字符串类型的数据吗!
- 如何写一个取得XML某子节点的路径XPATH的方法
- 请教一个问题
- 高分求助:将压缩包所有文件解压缩修改为逐个解压缩出单个文件
- 微軟官方論壇無解: 自繪ListBox的onPaint事件後滚动条好像不起做用了
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;namespace CA1
{
class Program
{
static void Main(string[] args)
{
string file = "sample.txt";//文件名
string filecontent = string.Empty;
int line = 2;//不需要的行
int curline = 1;
using (StreamReader sr = new StreamReader(file, Encoding.GetEncoding("GB2312")))
{
while (sr.Peek() != -1)
{
string tmp = sr.ReadLine();
if (line != curline)
{
if (filecontent != string.Empty) filecontent += "\r\n";
filecontent += tmp;
}
curline++;
}
}
//写回
using (StreamWriter sw = new StreamWriter(file, false, Encoding.GetEncoding("GB2312")))
{
sw.Write(filecontent);
}
Console.ReadLine();
}
}
}
string savestr= sd.ReadToEnd();
sd.Close();
int foundS1 = name.IndexOf(" ");
int foundS2 = name.IndexOf(" ", foundS1 + 1); if (foundS1 != foundS2 && foundS1 >= 0)
{ name = name.Remove(foundS1 + 1, foundS2 - foundS1);
} StreamWriter sw = File.CreateText("1.txt");
sw.WriteLine(savestr);
sw.Close();这是删除空格操作 自己写的 很容易看懂