Exemple #1
0
        public static string HighLight(string srcText, Dictionary <Color, IEnumerable <string> > colorKeywords)
        {
            RTFFormatter fmt = new RTFFormatter();
            Dictionary <string, Color> keyWordColorMap = new Dictionary <string, Color>();

            foreach (KeyValuePair <Color, IEnumerable <string> > kv in colorKeywords)
            {
                foreach (string keyWord in kv.Value)
                {
                    keyWordColorMap.Add(keyWord, kv.Key);
                }
            }

            StringBuilder buffer = new StringBuilder();

            buffer.Append(fmt.WriteHeader());

            string pattern = string.Format(@"\b({0})\b", Delimiter.ToString(keyWordColorMap.Keys, "|"));

            buffer.Append(Regex.Replace(srcText, pattern,
                                        delegate(Match m) { return(fmt.HighLight(m.Value, keyWordColorMap[m.Value])); }));

            buffer.Append(fmt.WriteFooter());
            return(buffer.ToString());
        }
Exemple #2
0
        public static string ReplaceMultipleWord(string text, Dictionary <string, string> replacements)
        {
            string pattern = string.Format("\b({0})\b", Delimiter.ToString(replacements.Keys, "|"));

            return(Regex.Replace(text, pattern, delegate(Match m) { return replacements[m.Value]; }));
        }