Tech Tip: Utility Method to Capitalize Each Word in the Title
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: August 7, 2025
The following method capitalize the first letter of each word in a given text.
// Method name: CapitalizeTitle #DECLARE($data_t : Text; $dilim_t : Text) : Text If (Count parameters<2) $dilim_t:=Char(Space) End if var $token_t : Text var $i : Integer var $data_c; $exclude_c : Collection $data_c:=Split string($data_t; $dilim_t) //; sk ignore empty strings) $exclude_c:=["a"; "an"; "the"; "and"; "but"; "or"; "nor"; "for"; "so"; "yet"; "at"; "by"; "for"; "from"; "in"; "of"; "on"; "to"; "up"; "with"; "as"] For ($i; 0; $data_c.length-1) $token_t:=$data_c[$i] If (Length($token_t)>0) $token_t:=Lowercase($token_t) Case of : ($exclude_c.findIndex(Formula($1.value=$2); $token_t)#-1) : ($token_t="@/@") $token_t:=CapitalizeTitle($token_t; "/") : ($token_t="@-@") $token_t:=CapitalizeTitle($token_t; "-") : ($token_t="@.@") $token_t:=CapitalizeTitle($token_t; ".") Else $token_t[[1]]:=Uppercase($token_t[[1]]) End case $data_c[$i]:=$token_t End if End for return $data_c.join($dilim_t) |
Example:
/ $result = "Utility Method to Capitalize Each Word in the Title" $result:=CapitalizeTitle("utility method to capitalize each word in the title") |