c# should i use string with regex matchs or not
I have a text that I am going to find matchs within that text and after that putting the results on array .
when I tried to make string array and string variables I found that it's really confusing to change from MatchCollection type to String type . and I get the error cannot convert .
what type of array and variables should I use ? and what is the need for string type . I was just using it since I deal with string.
I want to notice that I am going to compare between arrays to find common matchs
here is my full code so far c# regex array or list and which type string or what?
use:
string sample = "1a2b3c4d";
MatchCollection matches = Regex.Matches(sample, @"d");
List<string> matchesList = new List<string>();
foreach (Match match in matches)
matchesList.Add(match.Value);
matchesList.ForEach(Console.WriteLine);
or use LINQ:
List<string> matchesList2 = new List<string>();
matchesList2.AddRange(
from Match match in matches
select match.Value
);
matchesList2.ForEach(Console.WriteLine);
链接地址: http://www.djcxy.com/p/92834.html
上一篇: 如何让文本框只接受有效的电子邮件?
下一篇: 我应该使用字符串与正则表达式匹配或不