Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Pascal - How to capitalize each word in a string
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
August 19, 2013 7:07 AM
This is a small function I use for capitalizing each word in a string - obviously this works in most Pascal version. I use it in Delphi and Lazarus.
function Capitalize (const s: string): string;
var flag: boolean;
i : Byte;
t : string;
begin
if s<>'' then
begin
flag := true;
t := '';
for i := 1 to Length(s) do
begin
if flag then
t := t+ UpperCase(s)
else
t := t+ s;
flag := (s = ' ')
end;
end
else t:='';
result := t;
end;
(@bluegyn)
New Member
Joined: 11 years ago
Posts: 2
December 8, 2013 2:14 AM
The same fixed for Delphi, (char s[ i ] instead of string s ) , and added the - separator for capitalizing fistnames like anna-maria => Anna-Maria
Good job ***{:-
Note that your editor robot, automatiquely transforms the correct s [ i ] syntax in incorrect s ...
function Capitalize(const s: string): string;
{ //www.tweaking4all.com/forums/topic/pascal-how-to-capitalize-each-word-in-a-string/ }
var
flag: Boolean;
I: Byte;
t: string;
begin
if s <> '' then
begin
flag := true;
t := '';
for I := 1 to Length(s) do
begin
if flag then
t := t + UpperCase(s [ I ] )
else
t := t + LowerCase(s [ I ] );
flag := ((s [ I ] = ' ') or (s [ I ] = '-'))
end;
end
else
t := '';
result := t;
end;
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
December 8, 2013 5:08 AM
Thanks bluegyn for catching that ! 
Yeah, the editor and the backend have their issues ... I'm sorry about that.
It's interesting, because I just tried to edit the original post and guess what .. the [ i ] show correctly in the editor, just not when it's displayed as a post ..
.
(@bluegyn)
New Member
Joined: 11 years ago
Posts: 2
December 8, 2013 7:56 AM
The way found to fix this display bug was to add a space to the bracket like this [ i ]
Found a soluce => The Double Bracket (like double quoting tu put a quote in a Pascal string)
- You write : TEST [ [ i ] ]
- You get :TEST []
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
December 8, 2013 8:51 AM
Thanks again - I've been searching all morning to see if I can find a replacement editor or forum ... I've tried several editors and they all have been a pain ... not to mention that the backend keeps "modifying" content.
Thanks for the tip though!
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
December 8, 2013 10:32 AM
Managed to fix the issue ... it was a bbcode plugin that interpreted that as tag for setting text to italic ...
I really love the forum I'm using, except for the poor editor support