相关疑难解决方法(0)

打开一个文件并替换C#中的字符串

我试图找出打开现有文件的最佳方法,并将所有与声明的字符串匹配的字符串替换为新字符串,然后将其保存,然后关闭.

建议?

c#

36
推荐指数
4
解决办法
8万
查看次数

SSIS平面文件无法处理NUL(\ x00)值?

我正在尝试将数据从文本文件加载到数据库。我的源文件NUL以某种方式包含空字符(图片1)。

图片1

我只是将所有字段都设为一列(以分隔{CR}{LF})。然后我进行数据预览。

Picutre2

数据正是我们所需要的。但是,当我运行该程序包时,数据发生了变化,这与我在数据预览中看到的不一样。我添加了一个数据查看器以查看数据。

图片3

图片4

数字1在第一行消失(请参见红色)。似乎平面文件的读取以NUL字符结尾。但是我的行定界符是{CR}{LF},最后消失的数字1没有意义。谁能告诉我为什么?

sql-server null ssis etl flat-file

6
推荐指数
2
解决办法
490
查看次数

无法从文本文件中替换字符串

我正在尝试编写的代码是替换文本文件中的一串字.虽然我能够将文件的内容读取到控制台,但我无法替换字符串并将新字符串写入文件.

这是我的代码:

private static void filesys_created (object sender, FileSystemEventArgs e)
{
    using (StreamReader sr = new StreamReader(e.FullPath))
    {
        Console.WriteLine(sr.ReadToEnd());
        File.ReadAllText(e.FullPath);
        sr.Close();
    }

    using (StreamWriter sw = new StreamWriter(e.FullPath))
    {
        string text = e.FullPath.Replace("The words I want to replace");
        string newtext = "text I want it to be replaced with";

        sw.Write(e.FullPath, text);
        sw.Write(newtext);
        sw.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是.Replace正在删除文本文件中的所有内容,只插入目录的路径.

.net c#

2
推荐指数
1
解决办法
83
查看次数

如何编辑文本文件而不立即读取整个文件

我正试图解决这个问题:

编写一个程序,用文本文件中的"finish"替换每个子串"start".你能改写程序只替换整个单词吗?该程序是否适用于大文件(例如800 MB)?

我一直试图这样做,但显然你不能同时读写.如果有人可以查看我的代码并帮助我,那就太棒了.这是一个例外:

The process cannot access the file 'C:\Users\Nate\Documents\Visual Studio 2015\Projects\Chapter 15\Chapter 15 Question 7\Chapter 15 Question 7\TextFile.txt' because it is being used by another process.

你不必直接给我答案,而是告诉我这个过程.谢谢!

这是我目前的代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Chapter_15_Question_7
{
class Program
{
    static void Main(string[] args)
    {
        StreamReader reader = new StreamReader(
            @"C:\Users\Nate\Documents\Visual Studio 2015\Projects\Chapter 15\Chapter 15 Question 7\Chapter 15 Question 7\TextFile.txt");

        StreamWriter writer = new StreamWriter(
            @"C:\Users\Nate\Documents\Visual Studio 2015\Projects\Chapter 15\Chapter 15 Question 7\Chapter …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
802
查看次数

标签 统计

c# ×3

.net ×1

etl ×1

flat-file ×1

null ×1

sql-server ×1

ssis ×1