using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace c7_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button4_Click(object sender, EventArgs e) { string a1 = label1.Text; int len1 = a1.Length; textBox1.Text = len1.ToString(); } private void button5_Click(object sender, EventArgs e) { string a1 = label1.Text; string a2 = a1.ToUpper(); textBox1.Text = a2; } private void button1_Click(object sender, EventArgs e) { //字串尋找:IndexOf() //IndexOf("要尋找的內容"):找到這個字元或字串第一次出現的索引位置,如果找不到會回傳 - 1。 常用 //LastIndexOf("要找的內容"):找到這個字元或字串最後一次出現的索引位置,如果找不到會回傳 - 1. string a1 = label1.Text; int pos = a1.IndexOf("good"); if (pos == -1) textBox1.Text = "找不到"; else textBox1.Text = "找到了,位置在:" + pos.ToString(); } private void button2_Click(object sender, EventArgs e) { string a1 = label1.Text; int pos = a1.IndexOf("c++"); if (pos == -1) textBox1.Text = "找不到"; else textBox1.Text = "找到了,位置在:" + pos.ToString(); } private void button6_Click(object sender, EventArgs e) { string a1 = label1.Text; string a2 = a1.Replace("c#", "java"); textBox1.Text = a2; } } }