5. 設計一字串搜尋程式
namespace Q4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
var txt = File.ReadAllText(textBox1.Text);
textBox4.Text = txt;
var idx = txt.Replace("\r\n", "").IndexOf(textBox2.Text);
textBox3.Text = idx == -1 ? "未找到 " + textBox2.Text + " 字串" : (idx + 1).ToString();
}
}
}
Last updated