zoukankan      html  css  js  c++  java
  • C#正则表达式MatchCollection类浅析

    C#正则表达式MatchCollection类是什么含义呢?C#正则表达式MatchCollection类是如何使用的呢?那么本问就向你简单介绍C#正则表达式MatchCollection类的具体内容。

    AD:

    C#正则表达式MatchCollection类是什么呢?C#正则表达式MatchCollection类是如何使用的呢?下面让我们来具体的内容:

    下面通过介绍 .NET 框架的正则表达式类,熟悉一下.NET框架下的正则表达式的使用方法。

    C#正则表达式MatchCollection类表示非重叠匹配的序列

    该集合为只读的,并且没有公共构造函数。MatchCollection 的实例是由 Regex.Matches 属性返回的。使用 Regex 类的 Matches 方法,通过在输入字符串中找到的所有匹配填充 MatchCollection。下面代码示例演示了如何将集合复制到一个字符串数组(保留每一匹配)和一个整数数组(指示每一匹配的位置)中。

    C#正则表达式MatchCollection类实例应用:

    1. MatchCollection mc;  
    2.  
    3.  
    4. String[] results = new String[20];  
    5.  
    6.  
    7. int[] matchposition = new int[20];  
    8.  
    9.  
    10. Regex r = new Regex("abc");   
    11.  
    12. //定义一个Regex对象实例  
    13.  
    14. mc = r.Matches("123abc4abcd");   
    15.  
    16. for (int i = 0; i < mc.Count; i++)   
    17.  
    18. //在输入字符串中找到所有匹配  
    19. {  
    20.  
    21.  results[i] = mc[i].Value;   
    22.  
    23. //将匹配的字符串添在字符串数组中  
    24.  
    25.  matchposition[i] = mc[i].Index;   
    26.  
    27. //记录匹配字符的位置  
    28.  
    29. }   

    C#正则表达式MatchCollection类的基本内容就向你介绍到这里,希望对你了解和学习C#正则表达式MatchCollection类有所帮助。

  • 相关阅读:
    sort
    usaco-3.1-humble-pass
    usaco-3.1-inflate-pass
    usaco-3.1-agrinet-pass
    usaco-2.4-fracdec-pass
    usaco-2.4-comhome-pass
    usaco-2.4-cowtour-pass
    usaco-2.4-maze1-pass
    usaco-2.4-ttwo-pass
    usaco-2.3-concom-pass
  • 原文地址:https://www.cnblogs.com/soundcode/p/2208645.html
Copyright © 2011-2022 走看看