C# 遍历文本框

#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

 //----------分隔符号

// 功能 遍历html select 标签 中的键值对  加入到集合

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace HTML_下拉框_添加字典
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<string> list = new List<string>();
        private void button1_Click(object sender, EventArgs e)
        {
            //加入换行符
            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;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //去除select
            list.Clear();
            //
            foreach (string line in textBox1.Lines)
            {
                if (!line.Contains("select"))
                {
                    list.Add(line);
                }
            }
            textBox1.Text = string.Join("\r\n", list.ToArray());

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //输出数据
            string str;
            list.Clear();
            //输出主要数据
            foreach (string line in textBox1.Lines)   //遍历文本框
            {
                str = line.Replace("<option value=\"", "").Replace("\">", "#").Replace("</option>", ""); //替换数据
                list.Add(str.Insert(str.IndexOf("#") + 1, txtTJ.Text.Trim())); //插入指定数据
            }

            textBox1.Text = string.Join("\r\n", list.ToArray());  //集合转字符串 以回车符 分割

        }

    }
}

 //循环查找字符串并截取

  List<string> elements = new List<string>();
            int docIntT = 0;
            int zz = 0;
            docIntT = str.IndexOf(docStrT); //第一个标题位置
            for (int i = 0; i < str.Length; i++)
            {
                docIntT = str.IndexOf(docStrT, (docIntT+1));
                if (docIntT==-1)
                {
                    elements.Add(str.Substring(zz)); //从zz截取到最后
                    break; //未找到
                }
                elements.Add(str.Substring(zz, docIntT-zz));
                zz = docIntT;
            }

 

转载于:https://www.cnblogs.com/enych/p/8425674.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值