Skip to main content
Question

In Appian, Write an expression to check whether given string is a Palindrome or Not ?

A
Anonymous
May 20, 2026

Answer

A palindrome reads the same forward and backward. MADAM, LEVEL, and 12321 are palindromes, and HELLO is not.


In Appian you can check this by splitting the string into characters with a!forEach() and mid(), reversing them with reverse(), joining them with joinarray(), and comparing the result to the original with upper().


Appian Code:

a!localVariables(
local!text: "MADAM",
local!reversedText: joinarray(
reverse(
a!forEach(
items: enumerate(len(local!text)) + 1,
expression: mid(
local!text,
fv!item,
1
)
)
),
""
),

if(
upper(local!text) = upper(local!reversedText),
concat(local!text, " is a Palindrome"),
concat(local!text, " is not a Palindrome")
)
)


Output:

"MADAM is a Palindrome"


Code Explanation:


1. Store the input string

local!text: "MADAM"

Replace "MADAM" with any word to test other inputs.


2. Generate character positions with enumerate()

enumerate(len(local!text)) + 1

len() returns the length of the string, which is 5 for "MADAM". enumerate(5) returns {0, 1, 2, 3, 4}, and adding 1 turns that into the character positions {1, 2, 3, 4, 5}.


3. Extract each character with mid()

a!forEach(
items: enumerate(len(local!text)) + 1,
expression: mid(
local!text,
fv!item,
1
)
)

a!forEach() loops through the positions. mid() takes the string, a start position, and a length, so mid(local!text, fv!item, 1) returns the single character at each position. For "MADAM" the result is:


{"M", "A", "D", "A", "M"}


4. Reverse the characters with reverse()

reverse(
a!forEach(
items: enumerate(len(local!text)) + 1,
expression: mid(local!text, fv!item, 1)
)
)

reverse() flips the order of the array. For "MADAM" the array looks the same before and after, because the word is a palindrome:

{"M", "A", "D", "A", "M"}

For "HELLO" the reversed array is:

{"O", "L", "L", "E", "H"}


5. Join the characters with joinarray()

joinarray(
reverse(...),
""
)

joinarray() combines the array into one string. The second argument, "", is an empty delimiter, so nothing is inserted between characters. The array {"M", "A", "D", "A", "M"} becomes "MADAM", which is stored in local!reversedText.


6. Compare the original and reversed strings

if(
upper(local!text) = upper(local!reversedText),
concat(local!text, " is a Palindrome"),
concat(local!text, " is not a Palindrome")
)

upper() converts both strings to uppercase first, so the comparison ignores case for ordinary alphabetic input. If the strings match, the expression returns "MADAM is a Palindrome". If not, it returns something like "HELLO is not a Palindrome".



Solution 2: Check whether a string is a palindrome in Appian without reverse()


The first solution reversed an array of characters with reverse() and compared the joined result to the original. This version skips reverse() and builds the reversed string directly, by reading characters from the end of the input to the start with a!forEach(), mid(), and joinarray().


Appian Code

a!localVariables(
local!text: "MADAM",

local!reversedText: joinarray(
a!forEach(
items: enumerate(len(local!text)),
expression: mid(
local!text,
len(local!text) - fv!item,
1
)
),
""
),

if(
upper(local!text) = upper(local!reversedText),
concat(local!text, " is a Palindrome"),
concat(local!text, " is not a Palindrome")
)
)

Expected output:


text

MADAM is a Palindrome


Code Explanation:


1. Generate positions with enumerate()

enumerate(len(local!text))

"MADAM" has length 5, so this returns:

{0, 1, 2, 3, 4}


2. Extract characters in reverse order with mid()

mid(
local!text,
len(local!text) - fv!item,
1
)

Subtracting fv!item from the string length counts positions down from the end of the string:

fv!item

Calculated position

Character

0

5

M

1

4

A

2

3

D

3

2

A

4

1

M


3. Join the characters with joinarray()

joinarray(
a!forEach(...),
""
)

joinarray() combines the characters into one string, and the empty delimiter "" adds no separator. The array {"M", "A", "D", "A", "M"} becomes "MADAM".


4. Compare the original and reversed strings

if(
upper(local!text) = upper(local!reversedText),
concat(local!text, " is a Palindrome"),
concat(local!text, " is not a Palindrome")
)

If the two strings match, the input is a palindrome. If not, it isn’t.


Test with different inputs

Input

Reversed string

Result

MADAM

MADAM

Palindrome

LEVEL

LEVEL

Palindrome

RADAR

RADAR

Palindrome

HELLO

OLLEH

Not a palindrome

APPIAN

NAIPPA

Not a palindrome

This expression compares the whole input, including spaces and punctuation. To handle phrases like A man, a plan, a canal: Panama, you would first need to strip spaces and punctuation from the input.


Interview tip: be ready to explain why enumerate(len(local!text)) + 1 is used. enumerate() starts at zero, but mid() counts character positions from one, so adding 1 lines the two up.


Output:

Image 128

Try it yourself

Change the inputs or the expression and run it to see what it returns.

ri!text=

Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

JuniorExpressions