简体   繁体   中英

Remove last four characters in string that's part of url?

Here is my code:

<a href="<%= this.ResolveUrl("Search.aspx?id=" + lblGraphicNameValue.Text) %>" target="_blank">Search Related</a>

I want to take the text value of lblGraphicNameValue and remove the last four characters. Can I do this, and keep it inline? Or is this something I should do in the code behind?

Thanks!

I think this would work:

<a href="<%= this.ResolveUrl("Search.aspx?id=" + lblGraphicNameValue.Text.Substring(0, lblGraphicNameValue.Text.Length - 4) %>" target="_blank">Search Related</a>

or also this:

<a href="<%= this.ResolveUrl("Search.aspx?id=" + lblGraphicNameValue.Text.Remove(lblGraphicNameValue.Text.Length - 4) %>" target="_blank">Search Related</a>

I'm not sure, I have no experience with ASP.NET though so I don't know if it allows arbitrary code.

您还可以使用Remove方法:

lblGraphicNameValue.Text.Remove(lblGraphicNameValue.Text.Length - 4)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM