static string RevertLogoText(string checkText) { //初始化品牌的关键字字典 Dictionary<string, string[]> logoDict = new Dictionary<string, string[]>(); logoDict.Add("联想笔记本", new string[] { "len", "联想", "Think" }); logoDict.Add("samsung", new string[] { "三星", "samsung" }); //转换品牌字符串 System.Text.StringBuilder builder = new StringBuilder(); foreach (string str in checkText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { string logoText = str; foreach (KeyValuePair<string, string[]> item in logoDict) { if (Array.IndexOf(item.Value, str) >= 0) { logoText = item.Key; break; } } builder.AppendFormat("{0} ", logoText); } return builder.ToString(); }
来个循环替换即可。
string[] ss=new string[]{"Len","think","联想"}; string CheckText="len 联想 Think 三星 samsung "; foreach(string s in ss) { CheckText=CheckText.Replace(s,"联想笔记本"); }
类似于这样的做法