1

I am attempting to remove the last character from a URL string. Can I achieve this using Ampscript? It seems like it might be possible using lenght() and substring() and subtract() but I can't seem to bring them together to achieve this.

2
  • Did you try %%=Substring('abcdef',2,2)=%% ? See : developer.salesforce.com/docs/…
    – SF_user
    Jul 24, 2017 at 10:36
  • thanks for the response. Yes I did, however I won't always know the length of the URL, so can't specify in advance where to start the substring or the maximum lenght.
    – IR15
    Jul 24, 2017 at 10:47

1 Answer 1

2

You can do this using the Substring(1,2,3), Length(1) and Subtract(1,2) functions.

It is pretty easy and you need to supply the original string, the index you want to start with (1) and the length minus one as maximum length.

Example code:

%%[
    Var @firstString, @newString
    Set @firstString = "https://example.com/asdf/"
    Set @newString = Substring(@firstString, 1, Subtract(Length(@firstString), 1))
]%%

Related documentation:

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .