Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Scan a byte array for a specific character in a given encoding

$
0
0

Both System.Text.Encoding and its workhorse System.Text.Decoder provide straight-through means to decode raw bytes into a string when the string size is known in advance:

System.Text.Decoder.GetChars(Byte[],Int32,Int32,Char[],Int32)System.Text.Encoding.GetChars(Byte[],Int32,Int32)System.Text.Encoding.GetString(Byte[],Int32,Int32)

However, when that is not the case, and the string end must be determined by searching for a specific character (terminator; generally not a NUL), — what are the standard methods for this? Are there any functions like those below?

IndexOf(Char terminator,Byte[] buffer,Int32 start,Int32 maxsize)EnumerateChars(Byte[] buffer,Int32 start,Int32 count,SomeDelegateType callback)

Surprisingly, I was unable to find any, so I am wondering whether I am missing something obvious. If not, then how is this task usually accomplished — without making any assumptions on the encoding (take EBCDIC for example)?


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>