如下一个txt文件中,引号里面的内容读到一个二给数据中,其中红圈圈内容不要。
请问一下各位大虾和大神,该如何处理。谢谢了c#txt二维数据

解决方案 »

  1.   

    用正则取吧    xxxxxx([\s\S]+)xxxx
      

  2.   

    string tempStr = File.ReadAllText(@"C:\Users\myx\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
                    List<List<string>> _list = new List<List<string>>();
                    string pattern = @"(?i)time=(['""]?)(?<Time>[^'""]*?)\1\s*?id=(['""]?)(?<Id>[^'""]*?)\2\s*?name=(['""]?)(?<Name>[^'""]*?)\3\s*?";
                    pattern += @"card_src=(['""]?)(?<Card_src>[^'""]*?)\4\s*?type=(['""]?)(?<Type>[^'""]*?)\5\s*?";
                    foreach (Match m in Regex.Matches(tempStr, pattern))
                    {
                        List<string> _line = new List<string>();
                        _line.Add(m.Groups["Time"].Value);
                        _line.Add(m.Groups["Id"].Value);
                        _line.Add(m.Groups["Name"].Value);
                        _line.Add(m.Groups["Card_src"].Value);
                        _line.Add(m.Groups["Type"].Value);
                        _list.Add(_line);
                    }
                   string[][] data= _list.Select(a=>a.ToArray()).ToArray() ;//转为二维数组