日期:2014-05-17  浏览次数:20538 次

如何截取与更换字符串中的指定字符?求帮忙在线等!~~~
1. string as="xxx.aspx?zs=d300&cl=1023";
2. string as="xxx.aspx?cl=1023&zs=d300";
3. string as="xxx.aspx?cl=1023&zs=d300&at=ohk";

以上3种情况 如何让 参数zs  更换值呢?
string

------解决方案--------------------
string zsId = "232";//设置你要替换的值
            string str="xxx.aspx?cl=1023&zs=d300&at=ohk";
            Regex reg = new Regex("zs=[^&]*");
            str = reg.Replace(str, "zs=" +zsId );//
            Console.WriteLine(str);
------解决方案--------------------
 string replacestr="新替换的值";
            string htmls = @"你的html";
            htmls = Regex.Replace(htmls, @"(?<=zs=).*?(?=&
------解决方案--------------------
$)", replacestr);