In Appian, Write an expression to check whether given string is a Palindrome or Not ?
In Appian, Write an expression to check whether given string is a Palindrome or Not ?
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:
Output:
Code Explanation:
1. Store the input string
Replace "MADAM" with any word to test other inputs.
2. Generate character positions with enumerate()
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() 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:
4. Reverse the characters with reverse()
reverse() flips the order of the array. For "MADAM" the array looks the same before and after, because the word is a palindrome:
For "HELLO" the reversed array is:
5. Join the characters with joinarray()
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
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
Expected output:
text
Code Explanation:
1. Generate positions with enumerate()
"MADAM" has length 5, so this returns:
2. Extract characters in reverse order with mid()
Subtracting fv!item from the string length counts positions down from the end of the string:
| 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() 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 the two strings match, the input is a palindrome. If not, it isn’t.
Test with different inputs
Input | Reversed string | Result |
|---|---|---|
|
| Palindrome |
|
| Palindrome |
|
| Palindrome |
|
| Not a palindrome |
|
| 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:

Try it yourself
Change the inputs or the expression and run it to see what it returns.
Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms