Search code examples
urlrazorumbracotrimtruncate

Umbraco - Trim last five characters in current page url


Im getting the url of the current page using @CurrentPage.Url

It returns http://hostname/abcdefgh/

I wanted to trim out the last 5 characters of the URL

Req. URL http://hostname/abcd as the last five characters 'efgh/' is removed.

I tried using @umbraco.library.TruncateString(testString,-5,"") property to trim, but was unsuccessful.

Im new to umbraco. Any help would be highly appreciated.


Solution

  • I'd be interested to know the reason for doing this. Using the Remove method worked for me:

    @{
        string url = CurrentPage.Url;
        url = url.Remove(url.Length - 5);
    }