问题描述
我知道.NET的正则表达式可用于字符串,但是我需要一个byte []数组的实现..NET中是否有任何开源实现?除了C#之外,我是否可以使用byte [] regex来编写C#的包装程序?
I understand that .NET's regex works with strings, but I need an implementation for byte[] arrays. Are there any open source implementation in .NET? Does byte[] regex exists for any other programming language other than C# which I can use to build a wrapper for it in C#?
我的局限性是我必须留在字节数组中.因此无法进行任何字符串转换.
My limitation is that I have to stay within byte arrays. So cannot do any conversions to strings.
谢谢你的建议.
推荐答案
正则表达式适用于字符串.字节数组几乎可以包含任何数据.因此,如果要使用正则表达式,请使用用于对其进行编码的编码将此字节数组转换为字符串.例如,如果您的字节数组代表UTF-8编码的字符串:
Regular expressions work with strings. A byte array can contain just about any data. So if you want to use regular expressions convert this byte array into a string using the encoding that was used to encode it. For example if your byte array represents a UTF-8 encoded string:
byte[] buffer = ...
string foo = Encoding.UTF8.GetString(buffer);
// Go ahead and use regexes on foo
这篇关于是否有专门用于byte []数组的.NET众所周知的REGEX库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!