漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

{
            string strParaPath = @"E:\para.txt";
            string strCsPath = @"E:\cs.txt";
            FileStream fs = null;
            FileStream fscs = null;
            fscs = new FileStream(strCsPath, FileMode.Open, FileAccess.ReadWrite);
            FileStream fspara = new FileStream(strParaPath, FileMode.Open, FileAccess.Read);
            StreamReader srcs = new StreamReader(fscs);
            StreamReader srpara = new StreamReader(fspara);
            string strReadCs = "";
            string strReadPara = "";
            int intPos = 0;
            int intEndPos = 0;
            string strRealPara = "";
            string strWantPara = "";
            StringBuilder sb = new StringBuilder();
            //string bolIsDispEEEEGoalFctWeightForPln = "";
            while (!srpara.EndOfStream)
            {
                strReadPara = srpara.ReadLine();
                intPos = strReadPara.IndexOf("string");
                intEndPos = strReadPara.IndexOf("=");
                if (intPos == -1 || intPos >= intEndPos)
                {
                    continue;
                }
                strRealPara = strReadPara.Substring((intPos + 7), (intEndPos - intPos - 7));
                if(strRealPara.StartsWith("bol"))
                {
                    strWantPara = strRealPara.Replace("bol","str");
                   
                }


                while (!srcs.EndOfStream)
                {
                    strReadCs = srcs.ReadLine();
                    if (strReadCs.IndexOf(strRealPara) != -1)
                    {
                        sb.AppendLine(strReadCs.Replace(strRealPara, strWantPara));
                    }
                    else
                    {
                        sb.AppendLine(strReadCs);
                    }
                }
                StreamWriter sw = null;
                fscs.Dispose();
                fscs = new FileStream(strCsPath, FileMode.Truncate, FileAccess.ReadWrite);
                sw = new StreamWriter(fscs);
                sw.Write(sb.ToString());
                sw.Flush();
                sw.Dispose();
                sb = null;
                sb = new StringBuilder();
                fscs.Dispose();
                srcs.Dispose();
                fscs = new FileStream(strCsPath, FileMode.Open, FileAccess.ReadWrite);
                srcs = new StreamReader(fscs);
            }

            fscs.Dispose();

            MessageBox.Show("OK");
        }

posted on 2007-07-09 18:09  javaca88  阅读(125)  评论(0编辑  收藏  举报