zoukankan      html  css  js  c++  java
  • c#读取输入字符串,从数据源中查找以该字符串开头的所有字符串(使用正则表达式)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;//引用正则表达式需要的头文件
    using System.Threading.Tasks;

    namespace RegexApplication
    {
    class Program
    {
    static void Main(string[] args)
    {
    string i = Console.ReadLine();
    Regex r = new Regex(@"^"+i);// 创造以输入字符串开头的正则表达式
    string[] str = Data();//数据源
    foreach(string k in str){//在数据源中不断查找匹配项
    if(r.IsMatch(k)){
    Console.WriteLine(k);
    }
    }
    Console.ReadLine();
    }
    public static string[] Data() {

    string[] Mystring=new string[14];
    Mystring[0] = "aa123e";
    Mystring[1] = "aawwe";
    Mystring[2] = "aa3445";
    Mystring[3] = "abssdsf";
    Mystring[4] = "aatyu";
    Mystring[5] = "agfdh";
    Mystring[6] = "bbfdge";
    Mystring[7] = "bbf1222g";
    Mystring[8] = "bbfdge";
    Mystring[9] = "bbf";
    Mystring[10] = "bbfdge";
    Mystring[11] = "bbooouy";
    Mystring[12] = "byytre";
    Mystring[13] = "brrre";
    return Mystring;

    }
    }
    }

  • 相关阅读:
    不是结束,而是刚刚开始
    第七次作业
    用类做封装
    用户故事
    团队编程--MP3播放器
    结对编程作业
    四则运算
    四、小电视自动抽奖
    三、wss连接B站弹幕
    一、基础设计
  • 原文地址:https://www.cnblogs.com/huhuiliang/p/4359234.html
Copyright © 2011-2022 走看看