zoukankan      html  css  js  c++  java
  • 自己写的替换文件的内容,瞎写的,能用

    public void ReplaceString(string TargetString, string NewString)
    {
        string FileSrc = System.Web.HttpContext.Current.Server.MapPath("../admin/TextFile1.txt");
        if (File.Exists(FileSrc))
        {
            StreamReader sr = File.OpenText(FileSrc);
            string srrow = null;
            //读取文件所有的内容
            srrow = sr.ReadToEnd();
            if (srrow.IndexOf(TargetString) != -1)
            {
                //找到要找的字符串
                var a = srrow.IndexOf(TargetString);
                //要找的字符串后第一个"位置
                var b = srrow.IndexOf(""", a);
                //要找的字符串后第二个"位置
                var c = srrow.IndexOf(""", b + 1);
                //第一个"及之前的字符串
                string subtop = srrow.Substring(0, b + 1);
                //第二个"之后的字符串
                string subbottom = srrow.Substring(c);
                //拼接
                NewString = subtop + NewString + subbottom;
                //Response.Write(sub);
            }
            sr.Close();
            //写入
            StreamWriter sw = new StreamWriter(FileSrc, false);
            sw.WriteLine(NewString);
            sw.Close();
        }

  • 相关阅读:
    windows常规
    oracle常规操作
    idea使用
    java-maven
    java-rabbimq
    centos7 rabbitMq 安装教程
    Leetcode 332.重新安排行程
    Leetcode 334.递增的三元子序列
    Leetcode 331.验证二叉树的前序序列化
    Leetcode 330.按要求补齐数组
  • 原文地址:https://www.cnblogs.com/handsomer/p/3696501.html
Copyright © 2011-2022 走看看