Kevin
Kevin

Reputation: 4848

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!

Upvotes: 0

Views: 378

Answers (2)

p.s.w.g
p.s.w.g

Reputation: 149050

You can also use the Remove method:

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

Upvotes: 2

It&#39;sNotALie.
It&#39;sNotALie.

Reputation: 22814

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.

Upvotes: 4

Related Questions