/* This function is written en Progress 4GL 9.1C */
/* It receives a character string and returns the same, but */
/* - No leading spaces */
/* - No repeated spaces */
/* - Every word starts in upcase, and the other are lowcase */
/* Example -> Input " a BCDE gGHI ", output "A Bcde Gghi" */
/* Ezequiel Montoya Saldaña - Lima - Perú - 2016 */
FUNCTION _LikeProper RETURNS CHARACTER
( cString AS CHARACTER ) :
DEF VAR nCounter AS INTEGER.
/* Remove leading blank spaces */
cString = TRIM(cString).
/* Remove any repeated blank space */
DO WHILE INDEX(cString," ") <> 0 :
cString = REPLACE(cString," ", " ").
END.
/* Frst word starts in upcase, the rest are all lowcases */
cString = caps(substring(cString,1,1)) + lc(substring(cString,2)).
/* Final conversion */
DO nCounter = 2 TO LENGTH(cString) :
IF SUBSTRING(cString,nCounter,1) = " " THEN DO:
cString = SUBSTRING(cString,1,nCounter) + CAPS(SUBSTRING(cString,nCounter + 1,1)) + SUBSTRING(cString,nCounter + 2).
END.
END.
RETURN cString.
END FUNCTION.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.