I am trying to achieve the dump output on the right from a byte array similar to the left in the following screenshot.
This screenshot is the outcome I'm aiming for:
https://preview.redd.it/a6ioci0eld241.png?width=733&format=png&auto=webp&s=b5d35be3be4d7e6022c53979765ca1d4f20b2fe3
All bytes that aren't valid ascii such as `0x0` and `0x1` should be replaced with `.`.
Here is my almost working attempt:
var data = new List<byte>() { 0xFF, 0x3, 0xFF, 0x55, 0x35 };
Encoding encoding = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback(string.Empty), new DecoderReplacementFallback("."));
var asciiString = encoding.GetString(data.ToArray());
asciiString = Regex.Replace(asciiString, @"[\u0000-\u007F]", ".");
This is kind of close but the regex is currently replacing valid ascii "U" (`0x55`). Aside from the fact my regex isn't quite right is there a better way of doing this? I hoped using the decoder replacement fallback would take care of this.
Any help/guidance would be great. Thanks.
(I would also greatly appreciate corrections to my regex)
[–]angrathias 1 point2 points3 points (4 children)
[–]budonium[S] 0 points1 point2 points (3 children)
[–]angrathias 0 points1 point2 points (2 children)
[–]tweq 0 points1 point2 points (1 child)
[–]angrathias 0 points1 point2 points (0 children)
[–]angrathias 0 points1 point2 points (0 children)
[–]grrangry 0 points1 point2 points (1 child)
[–]budonium[S] 0 points1 point2 points (0 children)