怎么从字符串中。读到类似@。&。*的特殊符号。替换成汉字 例如string str=“你好&,我是@,你去*”;替换成你好刘翔,我是china,你去哪。最好有代码。。谢谢啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //定义规则 Dictionary<string, string> rules = new Dictionary<string, string>() { {"&","刘翔"}, {"@","chnai"}, {"*","哪"} }; string str="你好&,我是@,你去*"; foreach (var item in rules) { str = str.Replace(item.Key,item.Value); } //你好刘翔,我是chnai,你去哪" 那就往字典中循环加入变量,上面只不过是初始化后赋了初始值而已rules.Add(TKey,TValue); 用正则更方便 string str = "你好&,我是@,你去*"; Dictionary<string, string> dict = new Dictionary<string, string> { {"&","刘翔"}, {"@","china"}, {"*","哪"} }; MatchEvaluator func = (m) => { string value; if (dict.TryGetValue(m.Groups[0].Value, out value)) return value; else return m.Value; }; str = Regex.Replace(str, @"[&@\*]", func); Console.WriteLine(str); 怎样才能写好类??? 问个关于委托的问题 求一个发帖机的源代码!!!!C#实现! C#的StreamReader问题 请教一个调用Marshal.StructureToPtr方法的问题 DropDownList中能添加一个对象 或 对象指针吗? 请教一个DATAVIEW更新数据库的问题。 写的数据库数据查询服务报错(sqlserver),求助,谢谢!!! 收集了几个c#的程序,希望初学者能看看。高手不要进 在IDE环境下,如何在C#的asp应用程序中调用Access数据库? 在内存中操作DataTable后如何更新到数据库 如何实现VS工具栏拖动的效果
Dictionary<string, string> rules = new Dictionary<string, string>() {
{"&","刘翔"},
{"@","chnai"},
{"*","哪"}
};
string str="你好&,我是@,你去*";
foreach (var item in rules)
{
str = str.Replace(item.Key,item.Value);
}
//你好刘翔,我是chnai,你去哪"
rules.Add(TKey,TValue);
string str = "你好&,我是@,你去*";
Dictionary<string, string> dict = new Dictionary<string, string> {
{"&","刘翔"},
{"@","china"},
{"*","哪"}
}; MatchEvaluator func = (m) =>
{
string value; if (dict.TryGetValue(m.Groups[0].Value, out value))
return value;
else
return m.Value;
};
str = Regex.Replace(str, @"[&@\*]", func);
Console.WriteLine(str);