请指点两个问题

luhuayi 2004-07-24 08:58:19
1:怎么调用文本编辑器打开指定的文本
2:有一个文本文件,里面是一些ip,每个ip一行,要把这些
ip添加到listbox中去,怎么剔除相同的ip,使得listbox中的
items都是不同的ip。

谢谢!
...全文
94 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
luhuayi 2004-07-26
  • 打赏
  • 举报
回复
问题解决!非常感谢 upto(阿球|Smart Client) 和brightheroes(闭关|那一剑的风情) 两位大哥!
huangsuipeng 2004-07-25
  • 打赏
  • 举报
回复
噢,顶吧
peering08cn 2004-07-25
  • 打赏
  • 举报
回复
brightheroes(闭关|那一剑的风情):好东东,学习,拿来就可以用了
brightheroes 2004-07-25
  • 打赏
  • 举报
回复
关于读取文件
using System;
using System.IO;
using System.Collections;

namespace brightheroes
{
/// <summary>
/// 本类主要是为了以行的形式来处理文本文件
/// </summary>
public class TxtHelper
{
private int _LineNumber;
private string _FilePath;

/// <summary>
/// 文件总行数
/// </summary>
public int LineNumber
{
get{return this._LineNumber;}
}

/// <summary>
/// 文件路径
/// </summary>
public string FilePath
{
get{return this._FilePath;}
}

private ArrayList fileLine;

/// <summary>
/// 读取文件到ArrayList里面去,按照行号排列
/// </summary>
/// <param name="FilePath"></param>
public TxtHelper(string FilePath)
{
this._FilePath = FilePath;
StreamReader sr = new StreamReader(FilePath);
fileLine = new ArrayList();
int i = 0;
while(sr.Peek() > -1)
{
fileLine.Insert(i,sr.ReadLine());
i = i + 1;
}

this._LineNumber = i;
sr.Close();
}


/// <summary>
/// 返回某一行的内容
/// </summary>
/// <param name="LineIndex"></param>
/// <returns></returns>
public string ReadLine(int LineIndex)
{
return this.fileLine[LineIndex].ToString();
}

/// <summary>
/// 替换某一行的内容,如果不存在该行,则加入到末尾。
/// </summary>
/// <param name="LineIndex"></param>
/// <param name="LineValue"></param>
/// <returns></returns>
public void WriteLine(int LineIndex,string LineValue)
{
if(LineIndex <= this._LineNumber)
{
this.fileLine[LineIndex] = LineValue;
}
else
{
this.fileLine.Insert(this._LineNumber,LineValue);
this._LineNumber += 1;
}
}

/// <summary>
/// 插入某行到某处
/// </summary>
/// <param name="LineIndex"></param>
/// <param name="LineValue"></param>
public void InsertLine(int LineIndex,string LineValue)
{
if(LineIndex <= this._LineNumber)
{
this.fileLine.Insert(LineIndex,LineValue);
}
else
{
this.fileLine.Insert(this._LineNumber,LineValue);
this._LineNumber += 1;
}
}

/// <summary>
/// 覆盖原文件
/// </summary>
public void Save()
{
StreamWriter sw = new StreamWriter(this._FilePath);
for(int i = 0;i<this.fileLine.Count;i++)
{
sw.WriteLine(this.fileLine[i]);
}
sw.Close();
}

/// <summary>
/// 生成新的文件
/// </summary>
/// <param name="FilePath"></param>
public void Save(string FilePath)
{
StreamWriter sw = new StreamWriter(FilePath);
for(int i = 0;i<this.fileLine.Count;i++)
{
sw.WriteLine(this.fileLine[i]);
}
sw.Close();
}
}
}

Bob 2004-07-25
  • 打赏
  • 举报
回复
用 ListBox.Items.IndexOf 方法:

private void btnAdd_Click(object sender, System.EventArgs e)
{
if (listBox1.Items.IndexOf(txtText.Text) == -1)
listBox1.Items.Add(txtText.Text);
}
Bob 2004-07-25
  • 打赏
  • 举报
回复
1

System.Diagnostics.Process.Start(@"Notepad.exe", @"C:\BOOT.INI");

110,500

社区成员

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

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

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