完整读写txt 并提取{}里的内容
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 并提取{}里的内容的更多相关文章
- Flex读取txt文件里的内容(二)
Flex读取txt文件里的内容 自己主动生成的文件 LoadTxt-app.xml: <?xml version="1.0" encoding="utf-8&quo ...
- Flex读取txt文件里的内容(一)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/you23hai45/article/details/25248307 Flex读取txt文件里的内 ...
- 【转】js中通过docment.cookie获取到的内容不完整! 在浏览器的application里的cookie里可以看到完整的cookie,个别字段无法通过document.cookie获取。 是否有其他办法可以获取到??
js中通过docment.cookie获取到的内容不完整!在浏览器的application里的cookie里可以看到完整的cookie,个别字段无法通过document.cookie获取.是否有其他办 ...
- File操作-将txt里的内容写入到数据库表
package com.Cristin.File;//将txt里的内容写入到数据库表 import com.Cristin.MySQL.AddDataToDB;import org.testng.an ...
- Flex读取txt文件里的内容报错
Flex读取txt文件里的内容 1.详细错误例如以下 2.错误原因 读取文件不存在 var file:File = new File(File.applicationDirectory.nativeP ...
- [转载]C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 by 大龙哥 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char ...
- C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...
- WPF 读写TxT文件
原文:WPF 读写TxT文件 文/嶽永鹏 WPF 中读取和写入TxT 是经常性的操作,本篇将从详细演示WPF如何读取和写入TxT文件. 首先,TxT文件希望逐行读取,并将每行读取到的数据作为一个数组的 ...
- td里的内容宽度自适应 及 鼠标放上显示标题div title
td里的内容自适应宽度, 用 width:100%控制 strRight+="<td bordercolor='#DEDEDE' width='500px' height='50px' ...
随机推荐
- HDU1387:Team Queue
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1 ...
- 11.Selenium+Python案例--百度
一.具体代码实现 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionCh ...
- 反射ORM 三层(for oracle)
sql server and oracle 不同之处只在于: 1·参数@和: 2·自增和序列 3·oracle使用了存储过程以获得当前插入数据的ID DAL层的ORM using Oracle.Dat ...
- C语言 字符串中数字的运算
主函数中输入字符串"32486"和"12345",在主函数中输出的函数值为44831. #include <stdio.h> #include &l ...
- Java基础--比较器Comparator
Comparable接口和Comparator接口都是用来定义集合中的排序的,只是Comparable是在集合内部定义排序的实现,Comparator是在集合外部排序的实现. Comparable 的 ...
- php实现oracle操作
<?php function Query($sql,$prms){ $db = " (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ...
- boost::ASIO的同步方式和异步方式
http://blog.csdn.net/zhuky/article/details/5364574 http://blog.csdn.net/zhuky/article/details/536468 ...
- popd命令
popd命令用于删除目录栈中的记录:如果popd命令不加任何参数,则会先删除目录栈最上面的记录,然后切换到删除过后的目录栈中的最上面的目录. 语法 pushd(选项)(参数) 选项 +N:将第N个目录 ...
- L2-014. 列车调度(set的使用,最长递增子序列)
L2-014. 列车调度 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 火车站的列车调度铁轨的结构如下图所示. Figure ...
- HTML5的local storage
function clickLogin(){ var userName = $("#user").val().trim(); // console.log(userName); / ...