开发者

C# replace everything inbetween these tags

I want to override a meta-description tag if someone is on a product page of my site.

<meta name="description" content=" " /> 

The CMS I am using has this code in the pre-render method of its page template:

this.ltlTags.Text = this.HeaderTags; 

This populates the header with meta tags, CSS tags, script tags and all that.

I want to say something like this:

this.ltlTags.Text = this.HeaderTags.Replace(
    "everything inside the content attribute of the meta tag", "with this开发者_StackOverflow text"); 

In c# is there a way I can achieve this?


Something like this should work (untested):

this.ltlTags.Text = Regex.Replace(this.HeaderTags,
    "content=\"[^\"]*\"", "content=\"" + yourStuff + "\"");

It basically replaces content="<anything>" with content="<yourStuff>".


Could you replace the whole tag? And by that I mean

this.ltlTags.Text = this.HeaderTags.Replace("<meta name=\"description\" content=\" \" />",
                          "<meta name=\"description\" content=\"new text here\" />");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜