Are there any well know REGEX libraries for .NET specifically for byte[] arrays?

做~自己de王妃 提交于 2019-12-13 02:26:12

问题


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.

Thanks for the advice.


回答1:


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


来源:https://stackoverflow.com/questions/8907911/are-there-any-well-know-regex-libraries-for-net-specifically-for-byte-arrays

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!