//[Benchmark] public void readFull_char2() { string[] split = FULL_HEX.Split('\n'); char[] parsed = new char[2]; //the actual character: [0, 5] byte[] read; //the hex number the two characters represent: [0x05] int len; char c; foreach (string line in split) { len = line.Length; for (int i = 0; i < len; i++) { //parsed[0] = line[i]; ////Console.WriteLine($"string {line[i]}, parsed {Encoding.ASCII.GetBytes(parsed)[0].ToString("X")}"); if (i + 1 < len) { c = line[i]; parsed[0] = c; if (charValid(c)) { c = line[i + 1]; parsed[1] = c; if (charValid(c)) { read = FastHex.FromHexString(new string(parsed)); //Console.WriteLine($"Valid pair! {parsed[0]} {parsed[1]} = {read[0].ToString("X")}"); } } } } } }
public void ParseColors() { //menuStrip.ForeColor = Color.FromArgb(-1); int linenum = 0; bool flip = false; int currentSelectionStart = fixedRichTextBox1.SelectionStart; int currentSelectionLength = fixedRichTextBox1.SelectionLength; foreach (string line in fixedRichTextBox1.Lines) { char[] parsed = new char[2]; //the actual character: [0, 5] byte[] read; //the hex number the two characters represent: [0x05] int len; char c; len = line.Length; for (int i = 0; i < len; i++) { //parsed[0] = line[i]; ////Console.WriteLine($"string {line[i]}, parsed {Encoding.ASCII.GetBytes(parsed)[0].ToString("X")}"); if (i + 1 < len) { c = line[i]; parsed[0] = c; if (IsCharValid(c)) { c = line[i + 1]; parsed[1] = c; if (IsCharValid(c)) { read = FastHex.FromHexString(new string(parsed)); //flip = !flip; fixedRichTextBox1.SelectionStart = i + linenum; fixedRichTextBox1.SelectionLength = 2; fixedRichTextBox1.SelectionColor = Color.FromArgb(ColorUtil.Map[read[0]]); //richTextBox.SelectionColor = flip ? Color.DeepPink : Color.DeepSkyBlue; //Console.WriteLine($"Valid pair! {parsed[0]} {parsed[1]} = {read[0].ToString("X")}"); i++; //skip to the next character so that we don't get 1 color per character in a situation with 010203040 } } } } linenum += len + 1; } fixedRichTextBox1.SelectionStart = currentSelectionStart; fixedRichTextBox1.SelectionLength = currentSelectionLength; fixedRichTextBox1.SelectionColor = Color.White; }