Method for capitalizing the first letter of each word of entered text

I am new back on 4D after a long break and am interested in what methods are being used for Title Casing /Camel Casing of entered text.

Thanks
Reg

e.g.

Capitalize

<code 4D>
C_TEXT($1;$0)

ASSERT(Count parameters#0)

//Choose will evaluate the first case even if the condition is false
//$0:=Choose(Length($1)#0;Uppercase($1[1];)+Lowercase(Substring($1;2););$1)
$0:=Choose(Length($1)#0;Uppercase(Substring($1;1;1);)+Lowercase(Substring($1;2););$1)
</code 4D>

with

<code 4D>
C_TEXT($1;$0)

ASSERT(Count parameters#0)

ARRAY TEXT($words;0)
GET TEXT KEYWORDS($1;$words)

C_LONGINT($i)

For ($i;1;Size of array($words))
$0:=$0+Choose($i=1;"";" ")+Capitalize ($words{$i})
End for
</code 4D>

Hi Keisuke,

I like the idea to use GET TEXT KEYWORDS, but there is a flaw in the sample code you provided. It does not take other word delimiters than space into account when concatenating the result text. There will only be spaces left. No more points, commas,…

eg:
lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

gives:
Lorem Ipsum Dolor Sit Amet Consectetur Adipiscing Elit Sed Do Eiusmod Tempor Incididunt Ut Labore Et Dolore Magna Aliquam

Kind regards,
Koen

Thank you Miyako

This is great as i require the methods for correcting data entry of names and addresses only.

No punctuation is required.

Kind regards
Reg Blakey

Hi Koen

Although not necessary for my current requirements, I would be interested in any work-around you may be able to suggest for including punctuation in achieving Title Case for more complex text situations.

Thank you for you interest and input.

Reg Blakey

Hi Reg,

I don’t know if it is the most optimal code, but this is what I wrote a few years ago to CamelCase a text.

<code 4D>
C_TEXT($0;$1;$string)

$string:=Lowercase($1;*)

$wordSep:=" ,;:=?./\±_@#&(!)*+=%"+Char(Tab)+" "

$cap:=True
$length:=Length($string)
$result:=""
For ($i;1;$length)
$char:=Substring($string;$i;1)

Case of
: (Position($char;$wordSep;*)>0)
$cap:=True
$result:=$result+$char
: ($char=Char(Tab))
$cap:=True
$result:=$result+$char
: ($char=Char(Line feed))
$cap:=True
$result:=$result+$char
: ($char=Char(Carriage return))
$cap:=True
$result:=$result+$char

Else
If ($cap)
$result:=$result+Uppercase($char)
Else
$result:=$result+$char
End if
$cap:=False
End case
End for

$0:=$result
</code 4D>

I think the first optimization trick might be to replace the necessary characters with their uppercase counterpart in the originating string ($char) itself instead of building the $result string. And use the character index instead of substring.

Kind regards,
Koen