日期:2014-05-20 浏览次数:20774 次
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx string pattern = @"(?<=\()[^)]+(?=\))"; string[] result = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a => a.Value).ToArray(); /* * [0] "../images/changpinlist_01.jpg" string [1] "../images/changpinlist_02.jpg" string [2] "../images/changpinlist_03.jpg" string */
------解决方案--------------------
C:\Css.txt是你的文本内容
string CssStr = File.ReadAllText(@"C:\Css.txt", System.Text.Encoding.GetEncoding("GB2312")); List<string> list=new List<string>(); string pattern = @"(?is)(?<=\()[^()]*?(?=\))"; foreach(Match m in Regex.Matches(CssStr , pattern)) { list.Add(m.Value);//结果接在list中 }