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;

    }
    }
    }

  • 相关阅读:
    ZOJ 1002 Fire Net
    Uva 12889 One-Two-Three
    URAL 1881 Long problem statement
    URAL 1880 Psych Up's Eigenvalues
    URAL 1877 Bicycle Codes
    URAL 1876 Centipede's Morning
    URAL 1873. GOV Chronicles
    Uva 839 Not so Mobile
    Uva 679 Dropping Balls
    An ac a day,keep wa away
  • 原文地址:https://www.cnblogs.com/huhuiliang/p/4359234.html
Copyright © 2011-2022 走看看