更改youtube嵌入式链接的内容

时间:2010-07-06 13:39:24

标签: asp.net youtube

这是一个非常简单的复杂查询。我需要解决方案。我有一个youtube链接

 <----- width="480" height="350"><param name="movie"
 value="http://www.youtube.com/v/OORDOd6wRrE&amp;hl=en_US&amp;fs=1"></param><param
 name="allowFullScreen" value="true"></param><param
 name="allowscriptaccess" value="always"></param><----
 src="http://www.youtube.com/v/OORDOd6wRrE&amp;hl=en_US&amp;fs=1"
 type="application/x-shockwave-flash" allowscriptaccess="always"
 allowfullscreen="true" width="480" height="350"><---><----->

这是修改后的链接。好吧,我的问题是,我想改变视频的大小,意味着在整个字符串中我要用 width =“250”替换 width =“480” height =“350” height =“250”

我想使用ASP.Net

以编程方式更改这些参数

谢谢

2 个答案:

答案 0 :(得分:1)

那么似乎是什么问题?

这对我有用:

<object height="250" width="250">
    <param name="movie" value="http://www.youtube.com/v/OORDOd6wRrE"> 
    <param name="allowfullscreen" value="true"> 
    <param name="wmode" value="opaque"> 
    <embed src="http://www.youtube.com/v/OORDOd6wRrE" type="application/x-shockwave-flash" allowfullscreen="true" wmode="opaque" height="250" width="250"> 
</object>

但是,您应该根据height更改widthH/W ratio,以免电影失真。

修改

在看到OPs回答后,我想我明白他正在做什么。为此,我的建议是使用regular expressions,如此:

temp = Regex.Replace(strInput, "width=\"\d*\"", "width=\"250\"");
result = Regex.Replace(temp, "height=\"\d*\"", "height=\"250\"");

另外,请查看以下教程:Regular Expressions in ASP.NET

答案 1 :(得分:-1)

我得到了解决方案。

定义一个用户定义功能
private bool IsInt(string IntValue)
{
尝试
{
int iValue = int.Parse(IntValue);
}
catch(Exception Ex){return false;}

返回true;
}

    string str=txt_Links.Text;
    string lastNo = "";
    bool firstNoFound = false;
    for (int strIdx = 0; strIdx <= str.Length - 1; strIdx++)
    {
        if (IsInt(str.Substring(strIdx, 1)) == true)
        {
            lastNo = lastNo + str.Substring(strIdx, 1);
            firstNoFound = true;
        }
        else
        {
            if (firstNoFound == true)
            {
                //Page.Title = lastNo;
                str = str.Replace("width=\"" + lastNo + "\"", "width=\"250\"").Replace("height=\"" + lastNo + "\"", "height=\"250\"");
                lastNo = "";
                firstNoFound = false;
            }
        }
    }

    Response.Write(str);