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

C# 的replace 问题,急,在线等!
context.BindRegion(RegionName.Video_Video_Video_Embed_Code);
string EmbedHtml = string.Empty;
string embedinfo = string.Empty;
EmbedHtml= RegionProcessing.InnerText(context);
embedinfo= RegionProcessing.InnerText(context);
// select(script)
// replace(embedinfo,+,%20)
embedinfo = embedinfo.Replace("+","%20");
embedinfo = embedinfo.Replace("autostart=false","autostart=true");
// regexto(embedinfo,EmbedHtml,embed=%28[^&]+%29&,{1:d})
var regex = RegionProcessing.GetRegex("embed=([^&]+)&", RegexOptions.None);
var matches = regex.Matches(embedinfo);
if(matches.Count > 0){
EmbedHtml = string.Format("{1:d}",matches[0].Groups[0].Value,matches[0].Groups[1].Value);
}
EmbedHtml = HttpUtility.UrlDecode(EmbedHtml);
context.SetOutputValue(EmbedHtml.Trim());

想把autostart=false替换成autostart=true,带着=号不可以么?
小白坐等.....

------解决方案--------------------
可以啊,为啥说不可以?
------解决方案--------------------
你这样试试:embedinfo = embedinfo.Replace(@"autostart=false",@"autostart=true");
------解决方案--------------------
引用:
引用:可以啊,为啥说不可以?

我这死活replace不出来 - - !

字符串里没有"autostart=false"吧
------解决方案--------------------
这样可以啊。。你吧 embedinfo 输出来看看,是不是有空格之类的问题?
------解决方案--------------------
可以正确替换的。即使没有要替换的字符串,也不会出错。
你可以在控制台程序里测试一下,比如:
string embedinfo = "Sautostart=falsenE";
embedinfo = embedinfo.Replace("autostart=false", "autostart=true");
Console.Write(embedinfo);