Kbase 16906: How to Capitalize Each Word in a String
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to Capitalize Each Word in a String
The following code shows how to convert each word in a string so that
the first letter of each word is capitalized.
This code assumes the following things:
1) That each word is delimited by a space.
2) That you do not care about the capitalization (or lack of) for
the rest of the word (i.e. you only care about the first letter).
The following code is shown as both a procedure which can be used
with Version 7 and higher and as a function which can be used in
Version 8.2A and higher.
PROCEDURE Proper:
DEFINE INPUT-OUTPUT PARAMETER strPhrase AS CHARACTER NO-UNDO.
DEFINE VARIABLE intWordNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE strWord AS CHARACTER NO-UNDO.
DO intWordNumber = 1 TO NUM-ENTRIES(strPhrase," ").
ASSIGN strWord = ENTRY(intWordNumber,strPhrase," ")
SUBSTRING(strWord,1,1) = CAPS(SUBSTRING(StrWord,1,1))
ENTRY(intWordNumber,strPhrase," ") = strWord.
END.
END PROCEDURE.
FUNCTION Proper RETURNS CHARACTER (strPhrase AS CHARACTER):
DEFINE VARIABLE intWordNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE strWord AS CHARACTER NO-UNDO.
DO intWordNumber = 1 TO NUM-ENTRIES(strPhrase," ").
ASSIGN strWord = ENTRY(intWordNumber,strPhrase," ")
SUBSTRING(strWord,1,1) = CAPS(SUBSTRING(strWord,1,1))
ENTRY(intWordNumber,strPhrase," ") = strWord.
END.
RETURN strPhrase.
END FUNCTION.
Progress Software Technical Support Note # 16906