zoukankan      html  css  js  c++  java
  • 按照指定条件查找字符串

    实现效果:

      

    知识运用:

      Array类的FindAll()方法,根据指定条件在数组中检索元素 返回一个包含匹配项的数组  无匹配项则返回空数组

      public static T[] FindAll<T>(T[]array,Predicate<T>match)

      array:  要搜索从零开始的的一维Array数组

      match:  Predicate<T>,定义要搜索的元素的条件;

    实现代码:

            string[] str_area;
            private void button1_Click(object sender, EventArgs e)
            {
                if(textBox1.Text!=string.Empty){
                    string[] arr_return = Array.FindAll
                        (str_area,(s)=>s.Contains(textBox1.Text));
                    if (arr_return.Length > 0){ //判断找到
                        textBox2.Clear();
                        textBox2.Font = new Font("楷体", 15, FontStyle.Bold);
                            foreach(string s in arr_return){    //遍历添加
                                textBox2.Text += s + Environment.NewLine;
                            }
                    }
                    else { textBox2.Clear(); textBox2.Text = "没有找到"; }
                }else{
                    textBox2.Clear();
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                str_area=new string[]{"湖北湖南","江西江淮","河北河南","山西陕西","长治长子"};
                foreach(string str in str_area){
                    label2.Font = new Font("楷体",15,FontStyle.Bold);
                    label2.Text += str + Environment.NewLine;
                }
            }
    
  • 相关阅读:
    GeoServer与Spring MVC
    GeoServer二次开发1 hello Geoserver
    servlet的生命周期
    springboot打包出错,没有主清单
    空间数据库管理
    Gone with the wind
    谎言中的民众
    还是有些怀念这里啊
    MSN Protcol 学习笔记
    祝我的老师教师节快乐!
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10056193.html
Copyright © 2011-2022 走看看