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. oracle中merge的用法,以及各版本的区别 Create

    Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令,通过这个merge你能够在一个SQL语句中对一个 ...

  2. markdown的学习

    开始 语法 编辑器 sublime配置 图床 体验 开始 昨天晚上加上今天上午,折腾了算是一天的markdown编辑器. 原因是,为了写博客.在博客园写的东西,想法不到简书里,结果发现有部分乱码,以及 ...

  3. LeetCode第二题:Add Two Numbers

    You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...

  4. ASP.NET网站性能提升的几个方法

    1. HTTP 压缩 HTTP 压缩通常用于压缩从服务端返回的页面内容.它压缩HTTP请求和响应,这个会是巨大的性能提升.我的项目是基于Window Server 2003开发的,可以参考这篇文章. ...

  5. 机器学习:集成学习(OOB 和 关于 Bagging 的更多讨论)

    一.oob(Out - of - Bag) 定义:放回取样导致一部分样本很有可能没有取到,这部分样本平均大约有 37% ,把这部分没有取到的样本称为 oob 数据集: 根据这种情况,不对数据集进行 t ...

  6. 杂项-IIS:发布杂项

    ylbtech-杂项-IIS:发布杂项 1. 测试连接返回顶部 1.1.授权 无法验证对路径的访问. 1.2.详情信息 服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径.但是,IIS ...

  7. c++ 插入排序算法

    第一.算法描述       直插排序很容易理解,在我们打扑克牌的时候,每一次摸完牌,都会按数字大小或者花色,插入到合适的位置,直到摸完最后一张牌,我们手中的牌已经按大小顺序排列好了.这整个过程就是一个 ...

  8. linux yum 脚本实现

    yum 位于linux /usr/bin/yum yum命令是python脚本进行编写的(python 2.6) #!/usr/bin/python2.6 import sys try: import ...

  9. 跨数据文件删除flashback database

    Oracle flashback database的使用有一些限制,其中最主要的是flashback database不支持跨数据文件删除闪回和不支持跨数据文件shrink闪回.对于已经删除的数据文件 ...

  10. does not contain bitcode. You must rebuild it with

    *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE ...