当前位置: 首页 > news >正文

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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • llvm -O 经历过那些pass
  • Appium+python自动化15-查看webview上元素(DevTools)
  • Linux常用的操作指令
  • 如何fork比特币的源码并同步更新到本地
  • springboot-web进阶(三)——统一异常处理
  • SPA页面性能优化
  • Java单元测试之JUnit篇
  • Lagom学习(一)
  • docker 部署 flask(二)编写及生成镜像。
  • HDU 1846.Brave Game-巴什博奕
  • VC++ GetSafeHwnd()和GetSafeHandle()
  • hibernate框架学习笔记5:缓存
  • Spring 的autowired大坑
  • X86汇编快速入门
  • 块存储,文件存储,对象存储的层次关系
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • 【刷算法】求1+2+3+...+n
  • Apache的基本使用
  •  D - 粉碎叛乱F - 其他起义
  • export和import的用法总结
  • extjs4学习之配置
  • Fabric架构演变之路
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • JS学习笔记——闭包
  • maya建模与骨骼动画快速实现人工鱼
  • Mocha测试初探
  • Solarized Scheme
  • Work@Alibaba 阿里巴巴的企业应用构建之路
  • 技术发展面试
  • 前端技术周刊 2019-02-11 Serverless
  • 如何在GitHub上创建个人博客
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 用 Swift 编写面向协议的视图
  • - 语言经验 - 《c++的高性能内存管理库tcmalloc和jemalloc》
  • 深度学习之轻量级神经网络在TWS蓝牙音频处理器上的部署
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 阿里云IoT边缘计算助力企业零改造实现远程运维 ...
  • 回归生活:清理微信公众号
  • #HarmonyOS:Web组件的使用
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (2)STM32单片机上位机
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (分布式缓存)Redis持久化
  • (附源码)ssm失物招领系统 毕业设计 182317
  • (六)软件测试分工
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (使用vite搭建vue3项目(vite + vue3 + vue router + pinia + element plus))
  • (一)Docker基本介绍
  • .form文件_SSM框架文件上传篇
  • .net 7和core版 SignalR
  • .Net Attribute详解(上)-Attribute本质以及一个简单示例
  • .net Stream篇(六)
  • .one4-V-XXXXXXXX勒索病毒数据怎么处理|数据解密恢复
  • [ solr入门 ] - 利用solrJ进行检索