Replace无法完成多次替换 无语了,连个if else都不会用啊楼主 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 改成这样,勉强运行吧,不过看起来感觉不够简洁 string str = "123##$$"; if (str.Contains("#")) { str = str.Replace("#", "aa"); } if (str.Contains("$")) { str = str.Replace("$", "cc"); } Console.WriteLine(str);//结果为:123aaaa$$ str = str.Replace("$", "cc"); 中的"$" 此处被作为正则表达式解释运行了所以不成功可以像下面这样用正则去替换 Regex re = new Regex("[$]"); str = re.Replace(str, "cc");str = str.Replace("$", "cc"); 中的"$" 此处被作为正则表达式解释运行了所以不成功可以像下面这样用正则去替换 Regex re = new Regex("[$]"); str = re.Replace(str, "cc"); string str = "123##$$"; if (str.Contains("#")) { str = str.Replace("#", "aa"); } if (str.Contains("$")) { str = str.Replace("$", "cc"); }输出:123aaaacccc你原先esele if 有问题。 急求c#中access数据库的备份、还原程序! 请问一本英文书的中文名 ++我想窗体上的Icon不显示,但是任务栏上的icon(即taskbar icon)显示,怎么做? DataGridView使作 .net中熟悉activex的朋友请近来 Remoting连接与CS连接的问题 初学者:为什么要使用多线程? 事件问题 求C#高手帮忙 VS.net 2003中文版出来了吗? 调整 gridview 自动调整大小 entity framework 一个应用中是每次都new Context,销毁,还是复用直到程序关闭
string str = "123##$$";
if (str.Contains("#"))
{
str = str.Replace("#", "aa");
}
if (str.Contains("$"))
{
str = str.Replace("$", "cc");
}
Console.WriteLine(str);//结果为:123aaaa$$
Regex re = new Regex("[$]");
str = re.Replace(str, "cc");
str = str.Replace("$", "cc"); 中的"$" 此处被作为正则表达式解释运行了所以不成功可以像下面这样用正则去替换
Regex re = new Regex("[$]");
str = re.Replace(str, "cc");
{
str = str.Replace("#", "aa");
}
if (str.Contains("$"))
{
str = str.Replace("$", "cc");
}输出:123aaaacccc你原先esele if 有问题。