日期:2014-05-17  浏览次数:20461 次

如何在一个长的字符串中循环截取?
<ends>\n  
  <end xPos=\"0\" yPos=\"0\">\n  
  <properties>\n  
  <t1>aaaaaaaa<\/t1>\n  
  <t2>bbbbbbbb<\/t2>\n  
  <t3>cccccccc<\/t3>\n  
  <\/properties>\n  
  <\/end>\n  
  <end xPos=\"0\" yPos=\"0\">\n  
  <properties>\n  
  <t1>dddddd<\/t1>\n  
  <t2>eeeeee<\/t2>\n  
  <t3>ffffff<\/t3>\n  
  <\/properties>\n  
  <\/end>\n  
  <end xPos=\"0\" yPos=\"0\">\n  
  <properties>\n  
  <t1>gggggg<\/t1>\n  
  <t2>hhhhhh<\/t2>\n  
  <t3>iiiiii<\/t3>\n  
  <\/properties>\n  
  <\/end>\n
<\/ends>\n


这是一个字符串中的内容(dim str as string),我想将这里面的内容放在datalist或者dataset中,最终在网页中显示这种效果


t1 t2 t3

aaaaaaaa bbbbbbbb cccccccc

dddddddd eeeeeeee ffffffff

gggggggg hhhhhhhh iiiiiiii


想呈现这种效果,必须用截取字符串的方法,因为上面<ends></ends>是在一个string类型的字符串中

哪位高人能指点一下?

问题主要在于如何在一个字符串内循环查找、截取的问题,请指教 谢谢  


------解决方案--------------------
C# code
  string tempStr = File.ReadAllText(@"C:\Users\M\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));
            string pattern = @"(?i)<properties>[\s\S]*?<t1>([^<\s]+)<\\/t1>[\s\S]*?<t2>([^<\s]+)<\\/t2>[\s\S]*?<t3>([^<\s]+)<\\/t3>[\s\S]*?";

            var result = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a => new {
                t1=a.Groups[1].Value,
                t2 = a.Groups[2].Value,
                t3 = a.Groups[3].Value
            });
            /*
             * +        [0]    { t1 = "aaaaaaaa", t2 = "bbbbbbbb", t3 = "cccccccc" }    <Anonymous Type>
                +        [1]    { t1 = "dddddd", t2 = "eeeeee", t3 = "ffffff" }    <Anonymous Type>
                +        [2]    { t1 = "gggggg", t2 = "hhhhhh", t3 = "iiiiii" }    <Anonymous Type>

             */