KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method for Capitalizing First Character of Each Word of Text
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: February 6, 2023

The Utility Method - CapitalizeFirstChar() capitalizes the first character of each word of the text received as parameter and returns the resulting capitalized text.

The Utility Method is shown below:
CapitalizeFirstChar($input : Text) -> $output : Text

#DECLARE($input : Text)->$output : Text
var $textLength; $curChar : Integer

If (Count parameters=1)
  $output:=$input
  $textLength:=Length($output)
  If ($textLength>0)
    $output[[1]]:=Uppercase($output[[1]])
    For ($curChar; 1; $textLength-1)
      If (Position($output[[$curChar]]; " !&()-{}:;<>?/,.=+*")>0)
        $output[[$curChar+1]]:=Uppercase($output[[$curChar+1]])
      End if
    End for
  End if
End if


Example:

var $text1; $text2; $test1; $test2; $test3 : Text

$text1:="this is an example text."
$text2:="here is another example text!"

$test1:=CapitalizeFirstChar($text1)
$test2:=CapitalizeFirstChar($text1+" "+$text2+" all done!")
$test3:=CapitalizeFirstChar("last text to capitalize")

// $test1:= “This Is An Example Text.”
// $test2:= “This Is An Example Text. Here Is Another Example Text! All Done!”
// $test3:= “Last Text To Capitalize”