zoukankan      html  css  js  c++  java
  • 用StreamReader提取xml或者记事本里面的信息

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace testDataXml
    {
        class Program
        { 
            static void Main(string[] args)
            {
                Program pg = new Program();
                pg.test2(); 
                    
            }
    
            /// <summary>
            /// 循环一次性提取所有的数据(记事本也可以)
            /// </summary>
            void test1()
            {
                string tempString = "";
                string path = @"E:MyWorkasp.net	estxmldatafr003465.xml";
                string resettempString = "";
    
                using (StreamReader sr = new StreamReader(path))
                {
                    tempString = sr.ReadToEnd();
                    if (tempString.Length > 0)
                    {
                        resettempString = tempString.Replace(tempString.Substring(0, 1), "<");
    
                    }
    
                }
            }
    
    
    
            /// <summary>
            /// 循环提取xml每一行记录(记事本也可以)
            /// </summary>
            void test2()
            {
                string tempString = "";
                string path = @"E:MyWorkasp.net	estxmldatafr003465.xml";
    
    
                using (StreamReader sr = new StreamReader(path))
                {
                    
                    while (sr.Peek() >= 0) 
                    {
                        tempString = sr.ReadLine();
    
                        if (tempString == "hello word")
                        {
    
                            //把接下来获取的几行保存起来
                            
                        }
    
                    }
    
                }  
            }
        }
    }

    test1();方法的结果

    test2();方法的结果

  • 相关阅读:
    android sdk配置
    ptmalloc, dlmalloc
    Longest common subsequence problem
    handless UI (direct UI)
    poj 题目分类
    2010有道难题练习赛2
    JAVA内存模型
    wxformbuilder+WxWidgets下载编译使用
    这几天弄一下
    活用regex的例子 zz
  • 原文地址:https://www.cnblogs.com/suntanyong88/p/4583369.html
Copyright © 2011-2022 走看看