简体   繁体   English

使用C#FileStream作为Regex.Match方法的输入

[英]Using C# FileStream as input to Regex.Match method

I am trying to write a program using C# in Visual Studio on Windows 10 and have found that the Regex.Matches method takes two strings one for the input and the other for the regex string to use. 我试图在Windows 10上的Visual Studio中使用C#编写程序,发现Regex.Matches方法采用两个字符串,一个用于输入,另一个用于regex字符串。 My input is a FileStream and this doesn't appear to convert to string . 我的输入是FileStream ,它似乎没有转换为string It is an array like structure. 它是一个类似数组的结构。

How to use regular expressions upon a file stream? 如何在文件流上使用正则表达式? I have done some searching but have not come up with anything conclusive. 我已经做了一些搜索,但还没有得出结论。

Regex is intended for matching text patterns, not binary patterns. 正则表达式用于匹配文本模式,而不是二进制模式。 Is your file a text file? 您的文件是文本文件吗? If so, use File.ReadAllText() instead of FileStream. 如果是这样,请使用File.ReadAllText()而不是FileStream。 If not, you'll need to explain your data and what you are trying to do so we can offer a better solution. 如果没有,您将需要解释您的数据以及您要做什么,以便我们提供更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM