How to check if string is a palindrome in open edge progress 4gl

1.2k views Asked by At

How can I check whether a given string is a palindrome or not in open edge progress 4gl? Is there any reverse string function built-in with progress 4gl?

FUNCTION reverseString RETURNS CHARACTER (
   INPUT i_c AS CHARACTER
):



   DEFINE VARIABLE cresult AS CHARACTER   NO-UNDO.
   DEFINE VARIABLE ii      AS INTEGER     NO-UNDO.

   DO ii = LENGTH( i_c ) TO 1 BY -1:
      cresult = cresult + SUBSTRING( i_c, ii, 1 ).
   END.
   RETURN cresult.

END FUNCTION.

display reverseString( "asdf" ).
1

There are 1 answers

0
Tom Bascom On

The complete OpenEdge doc set can be found here:

https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview.aspx

As you can see, there is no built-in reverse string function.

A function like the one that you illustrate above is what you need.

To determine if a string is a palindrome using that function:

myString = "asdf".
if myString = reverseString( myString ) then
  message "yes," myString "is a palindrome".
 else
  message "no," myString "is not a palindrome".