0

I'm trying the below code so that if the last character of the string is S, then a variable will equal to Z. Am currently getting an error :( Appreciate your help

%%[
SET @EndswithS = Substring(@Name, SUBTRACT(Length(@Name), 1), 225)
IF @EndswithS = 's' THEN SET @nameend = 'Z'
ELSE SET @nameend = 'Y'

2

I broke it down a little, so it's easier for you to understand how this works:

%%[
set @name = [set name here]
set @namelenght = Length(@name)
SET @EndswithS = Substring(@name,@namelenght,1)
IF @EndswithS == 's' THEN 
 SET @nameend = 'Z'
ELSE SET @nameend = 'Y'
ENDIF
]%%
0

I've tested using the answers provided here and on this thread.

The following should return the last two characters from input string.

%%=Substring("abcdefg",Length("abcdefg") - 2,2)=%%

However the minus in "-2" does not work and need to use Subtract.

Here is my final code.

%%[

SET @Name = Name
SET @NameLength = Length(@Name)
SET @EndswithS = Substring(@Name, Subtract(Length(@Name),0),1)
SET @EndS = Substring(@Name, Subtract(Length(@Name),1),1)

IF @EndswithS == 's' THEN
 SET @nameend = 'Z'
 ELSE SET @nameend = 'Y'

ENDIF
]%%

In my code the @EndswithS selects the 1st character from end, where as @EndS selects the 2nd character from end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.