using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
//txt路径
static string Path = "C:\\wb2.txt";
static string path = "E:\\jrf\\文本2.txt";
protected void Page_Load(object sender, EventArgs e)
{
ReadTxtContent(Path);
Write(path);
}
/// <summary>
/// 读取txt内容
/// </summary>
/// <param name="Path">文件地址</param>
public string ReadTxtContent(string Path)
{
StreamReader sr = new StreamReader(Path, Encoding.Default);
string content;
string f="";
while ((content = sr.ReadLine()) != null)//按行输出
{
f+=content;
}
//截取{}的内容 再写入txt文件
var array = f.Split('{');
f = "";
foreach (var x in array)
{
if (x.Contains("}"))
{
string[] n = x.Split('}');
f += "{" + n[] + "}" + "\r\n";
}
}
return f;
}
/// <summary>
/// 获取ReadTxtContent返回的内容写入.txt
/// </summary>
/// <param name="path"></param>
public void Write(string path)
{
//FileMode.Append为不覆盖文件效果.create为覆盖
FileStream fs = new FileStream(path, mode: FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
//开始写入 sw.Write(ReadTxtContent(Path));
//清空缓冲区
sw.Flush();
//关闭
sw.Close();
fs.Close();
}
}
}

完整读写txt 并提取{}里的内容的更多相关文章

  1. Flex读取txt文件里的内容(二)

    Flex读取txt文件里的内容 自己主动生成的文件 LoadTxt-app.xml: <?xml version="1.0" encoding="utf-8&quo ...

  2. Flex读取txt文件里的内容(一)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/you23hai45/article/details/25248307  Flex读取txt文件里的内 ...

  3. 【转】js中通过docment.cookie获取到的内容不完整! 在浏览器的application里的cookie里可以看到完整的cookie,个别字段无法通过document.cookie获取。 是否有其他办法可以获取到??

    js中通过docment.cookie获取到的内容不完整!在浏览器的application里的cookie里可以看到完整的cookie,个别字段无法通过document.cookie获取.是否有其他办 ...

  4. File操作-将txt里的内容写入到数据库表

    package com.Cristin.File;//将txt里的内容写入到数据库表 import com.Cristin.MySQL.AddDataToDB;import org.testng.an ...

  5. Flex读取txt文件里的内容报错

    Flex读取txt文件里的内容 1.详细错误例如以下 2.错误原因 读取文件不存在 var file:File = new File(File.applicationDirectory.nativeP ...

  6. [转载]C#读写txt文件的两种方法介绍

    C#读写txt文件的两种方法介绍 by 大龙哥 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char ...

  7. C#读写txt文件的两种方法介绍

    C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...

  8. WPF 读写TxT文件

    原文:WPF 读写TxT文件 文/嶽永鹏 WPF 中读取和写入TxT 是经常性的操作,本篇将从详细演示WPF如何读取和写入TxT文件. 首先,TxT文件希望逐行读取,并将每行读取到的数据作为一个数组的 ...

  9. td里的内容宽度自适应 及 鼠标放上显示标题div title

    td里的内容自适应宽度, 用 width:100%控制 strRight+="<td bordercolor='#DEDEDE' width='500px' height='50px' ...

随机推荐

  1. python函数之sorted与sort

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. sorted(iterable,key=None,revers ...

  2. CF 622F The Sum of the k-th Powers——拉格朗日插值

    题目:http://codeforces.com/problemset/problem/622/F 发现 sigma(i=1~n) i 是一个二次的多项式( (1+n)*n/2 ),sigma(i=1 ...

  3. grafana 4.0.2 + openfalcon query 1.4.3

    转:http://blog.csdn.net/vbaspdelphi/article/details/53884282 grafana 4.0.2 加上官方app自带的openfalcon插件, 可以 ...

  4. RSA公钥,私钥和数字签名通用理解

    一.公钥加密 假设一下,我找了两个数字,一个是1,一个是2.我喜欢2这个数字,就保留起来,不告诉你们(私钥),然后我告诉大家,1是我的公钥. 我有一个文件,不能让别人看,我就用1加密了.别人找到了这个 ...

  5. 【转】CSG(Closed Subscriber Group)闭合用户组

    CSG是3GPP R8中引入的概念,定义为闭合用户组.有以下特点: 1. 每个CSG由一个CSG ID标识 2. 同一用户可属于多个CSG,用户与CSG的关系就好比签约,启用了CSG小区只会允许签约用 ...

  6. Zookeeper学习(八):Zookeeper的数据发布与订阅模式

     http://blog.csdn.net/ZuoAnYinXiang/article/category/6104448 1.发布订阅的基本概念        1.发布订阅模式可以看成一对多的关系:多 ...

  7. 【转】href="#"与"javascript:void(0);"的区别

    在工作中,如果我们想把a标签中的链接置成空链接,我们一般会用两种方法: 1 <a href="#" target="_blank"></a&g ...

  8. C Primer Plus学习笔记(五)- C控制语句:循环

    伪代码的概念: 伪代码是一种用简单的句子表示程序思路的方法,它与计算机语言的形式相对应.伪代码有助于设计程序的逻辑.确定程序的逻辑无误之后,再把伪代码翻译成实际的编程代码.使用伪代码的好处之一是,可以 ...

  9. c# webapi2 实用详解

    本文介绍webapi的使用知识 发布webapi的问题 配置问题 webapi的项目要前端访问,需要在web.config配置文件中添加如下配置 在system.webServer节点下面添加 < ...

  10. 一个hitbernate配置文件,带几个表(注意mapping);如果连接字符串没有设置utf-8,向insert mysql 会产生乱码(utf8 或 utf-8)

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuratio ...