zoukankan      html  css  js  c++  java
  • 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, "
    ");
                for (int i = 0; i < str.Length; i++)
                {
                    one = str.IndexOf("</option>", ++one); //第二次出现的位置                
                    if (one == -1)
                    {
                        break;//未找到
                    }
                    else
                    {
                        str = str.Insert(one + 9, "
    ");
                    }
                }
                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("
    ", 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, "
    ");
                for (int i = 0; i < str.Length; i++)
                {
                    one = str.IndexOf("</option>", ++one); //第二次出现的位置                
                    if (one == -1)
                    {
                        break;//未找到
                    }
                    else
                    {
                        str = str.Insert(one + 9, "
    ");
                    }
                }
                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("
    ", 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("
    ", 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;
                }
  • 相关阅读:
    2017级面向对象程序设计 作业三
    2017级面向对象程序设计 作业二
    2017级面向对象程序设计 作业一
    寒假作业之总结
    寒假第三次作业
    寒假第二次作业 与电梯有关的代码问题
    我印象中最深刻的三位老师
    Alpha冲刺Day5
    Alpha冲刺Day4
    Alpha冲刺Day3
  • 原文地址:https://www.cnblogs.com/enych/p/8425674.html
Copyright © 2011-2022 走看看