您的位置:首页 > 博客中心 > 电脑问题 >

C# 遍历文本框

时间:2022-03-18 07:55

#region 文本框指定位置加入回车符
        private void button1_Click(object sender, EventArgs e)
        {
            #region 
            //  查询首字母位置
            //string str = "ab0ab0ab0ab0";
            //int one = str.IndexOf("0"); //返回0出现的位置【索引】

            //for (int i=0;i<str.Length;i++)
            //{
            //    one = str.IndexOf("0", ++one); //第二次出现的位置
            //    if (one==-1)
            //    {
            //        break;//未找到
            //    }
            //    MessageBox.Show(one.ToString());
            //}
            #endregion

            string str = textBox1.Text.Trim();
            int one = str.IndexOf("</option>"); //返回0出现的位置【索引】
            str = str.Insert(one + 9, "\r\n");
            for (int i = 0; i < str.Length; i++)
            {
                one = str.IndexOf("</option>", ++one); //第二次出现的位置                
                if (one == -1)
                {
                    break;//未找到
                }
                else
                {
                    str = str.Insert(one + 9, "\r\n");
                }
            }
            textBox1.Text = str;
        }
        #endregion
        #region list转string  去除text指定行
        List<string> list = new List<string>();
        private void button2_Click(object sender, EventArgs e)
        {
            list.Clear();
            //
            foreach (string line in textBox1.Lines)
            {
                if (!line.Contains("select"))
                {
                    list.Add(line);
                }
            }
            textBox1.Text= string.Join("\r\n", list.ToArray());
        }
        #endregion

 

热门排行

今日推荐

热门手游