Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文件帮助程序在读取记录之前更改记录行_C#_Filehelpers - Fatal编程技术网

C# 文件帮助程序在读取记录之前更改记录行

C# 文件帮助程序在读取记录之前更改记录行,c#,filehelpers,C#,Filehelpers,我正在使用图书馆阅读一个巨大的文件。在阅读下面的记录之前,我想更改记录行 static void engine_BeforeReadRecord(object sender, BeforeReadRecordEventArgs<object> e) { if (e.RecordLine.Contains(@"\|")) e.RecordLine.Replace(@"\|", ""); } 静态无效引擎\u BeforeR

我正在使用图书馆阅读一个巨大的文件。在阅读下面的记录之前,我想更改记录行

   static void engine_BeforeReadRecord(object sender, BeforeReadRecordEventArgs<object> e)
    {
        if (e.RecordLine.Contains(@"\|"))
            e.RecordLine.Replace(@"\|", "");
    }
静态无效引擎\u BeforeReadRecord(对象发送方,BeforeReadRecordEventArgs e)
{
if(例如,RecordLine.Contains(@“\\”))
e、 记录行。替换(@“\\”,“”);
}
他们的在线帮助还说,这是有可能改变的

Note: if you change the RecordLine the engine use the changed value This can be useful in some cases but you must be carefull 注意:如果更改记录行,引擎将使用更改后的值 这在某些情况下是有用的,但你必须小心
但它不起作用。是否有任何问题妨碍了我的工作?

我假设您正在设置事件

engine.BeforeReadRecord += engine_BeforeReadRecord;

使用最新版本的库,您可以做到这一点

您还可以使用INotifyRead接口:


假设记录行是一个字符串,则调用
.Replace()
函数,但此函数不会内联修改字符串-它返回一个新字符串。您需要将结果分配到某个位置:

if (e.RecordLine.Contains(@"\|"))
    e.RecordLine = e.RecordLine.Replace(@"\|", "");

谢谢Joel,我之前试过了,结果显示e.RecordLine是只读的。@RajanR.G在这种情况下,您需要同时使用我的答案和MarcosMeli的答案。另外-不需要if语句-如果字符串不包含文本,则替换调用将无效。谢谢Joel,最新版本与您的解决方案完美配合。谢谢Marcos,我将下载最新版本,并在作业中尝试此操作。最新版本与Joel的回答完美配合。感谢您提供的精彩图书馆。