#region "MIRC Colors" static public RTF colorCode(string RTFWorkBuffer, string zString) { //Start the new buffer string RTFContentBuffer; RTFContentBuffer = "{\\rtf1\\ansi {\\colortbl;"; RTFContentBuffer += "\\red255\\green255\\blue255;"; //0 RTFContentBuffer += "\\red0\\green0\\blue0;"; //1 RTFContentBuffer += "\\red0\\green0\\blue128;"; //2 RTFContentBuffer += "\\red0\\green128\\blue0;"; //3 RTFContentBuffer += "\\red255\\green0\\blue0;"; //4 RTFContentBuffer += "\\red128\\green0\\blue0;"; //5 RTFContentBuffer += "\\red128\\green0\\blue128;"; //6 RTFContentBuffer += "\\red255\\green128\\blue0;"; //7 RTFContentBuffer += "\\red255\\green255\\blue0;"; //8 RTFContentBuffer += "\\red0\\green255\\blue0;"; //9 RTFContentBuffer += "\\red0\\green128\\blue128;"; //10 RTFContentBuffer += "\\red0\\green255\\blue255;"; //11 RTFContentBuffer += "\\red0\\green0\\blue255;"; //12 RTFContentBuffer += "\\red255\\green0\\blue255;"; //13 RTFContentBuffer += "\\red125\\green128\\blue125;"; //14 RTFContentBuffer += "\\red200\\green200\\blue200;}"; //15 string tTrans; if (zString != "") { //Escape all bad characters zString = zString.Replace("\\", "\\\\"); zString = zString.Replace("{", "\\{"); zString = zString.Replace("}", "\\}"); zString = zString.Replace(" ", "\\ "); //Replace crlf with the rtf linebreak zString = zString.Replace("\r\n", "\\line "); //Start everyline as normal zString = "\\txflTextFlow2\\cf0\\highlight0" + zString; //Match Colors // Dim tColors As New Regex("()(?(\d){1,2})(,(?\d{1,2}))?(?[ ])?", RegexOptions.Multiline) Regex tColors = new Regex("()(?(\\d){1,2})(,(?\\d{1,2}))?", RegexOptions.Multiline); tTrans = tColors.Replace(zString, returnParsedColor); //If there is still the color control character, replace it with normalness tTrans = tTrans.Replace("", "\\cf0\\highlight0"); //Match Bolds Regex tBold = new Regex("()(?[^]+)()", RegexOptions.Multiline); tTrans = tBold.Replace(tTrans, returnParsedBold); //If the bold character exists, then it goes to the end of the line, so replace it //with a new rtf bold, and then end the line with a bold end if (tTrans.Contains("")) { tTrans = tTrans.Replace("", "\\b "); tTrans += "\\b0"; } //Match Underlines Regex tUnderLined = new Regex(string.Format("({0})(?[^{0}]+)({0})", '\u001F'), RegexOptions.Multiline); tTrans = tUnderLined.Replace(tTrans, returnParsedUnderLine); //If the underline character exists, then it goes to the end of the line, so replace it //with a new rtf underline, and then end the line with a underline end if (tTrans.Contains('\u001F')) { tTrans = tTrans.Replace("\u001F", "\\ul "); tTrans += "\\ul0"; } RTFWorkBuffer += tTrans; } //Update the buffers RTFContentBuffer += RTFWorkBuffer; RTF tStruct; tStruct.RTFContentBuffer = RTFContentBuffer; tStruct.RTFWorkBuffer = RTFWorkBuffer; return tStruct; } #region "Regex Parsers" static public string returnParsedBold(Match m) { try { string tValue = m.Groups["text"].Value; string OutText; OutText = "{bold}" + tValue + "{!bold}"; return OutText; } catch (Exception except) { throw except; //MessageBox.Show("Errored (Variable Parse): " + except.Message); } } static public string returnParsedUnderLine(Match m) { try { string tValue = m.Groups["text"].Value; string OutText; OutText = "{underline}" + tValue + "{!underline}"; return OutText; } catch (Exception except) { throw except; //MessageBox.Show("Errored (Variable Parse): " + except.Message); } } static public string returnParsedColor(Match m) { try { string tValue = m.Groups["color"].Value; string tValue2 = m.Groups["color2"].Value; // Dim tValue3 As String = m.Groups("space").Value //MsgBox(tValue & tValue2 & " " & tValue3.Length) int Color1; int Color2; string OutText = ""; if (int.TryParse(tValue,out Color1)) { //Color1 = int.Parse(tValue); if (Color1 > 15 || Color1 < 0) { Color1 = -1; } } else { Color1 = -2; } if (int.TryParse(tValue2, out Color2)) { // Color2 = int.Parse(tValue2); if (Color2 > 15 || Color2 < 0) { Color2 = -1; } } else { Color2 = -1; } if (Color1 > -1) { OutText = "{foreground:" + (Color1) + "}"; if (Color2 > -1) { OutText += "{background:" + Color2 + "}"; } } // If tValue3.Length = 1 Then //OutText += " "; // End If return OutText; } catch (Exception except) { throw except; //MessageBox.Show("Errored (Variable Parse): " + except.Message); } } #endregion static public string colorStrip(string zString) { try { Regex tColors = new Regex("()(?(\\d{1,2})(,\\d{1,2})?)", RegexOptions.IgnoreCase); zString = tColors.Replace(zString, ""); zString = zString.Replace("", ""); zString = zString.Replace("", ""); zString = zString.Replace("\u001F", ""); zString = zString.Replace("\u000F", ""); return zString; } catch (Exception ex) { throw ex; //MessageBox.Show("Color Parsing Error"); } } public struct RTF { public string RTFWorkBuffer; public string RTFContentBuffer; }