首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 的replace 有关问题,

2013-04-22 
C# 的replace 问题,急,在线等!context.BindRegion(RegionName.Video_Video_Video_Embed_Code)string Embe

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);

热点排行