SOLVED Capitalize word after each space not working lazarus / 21-General ---------------------------------------------------------------------- DreamVB · 2022-07-03 22:41 Hi, I been making a little text editor and I am adding in some features to deal with converting a selection of text, I got the uppercase,lowercase and toggle-case working however I am stuck on the capitalize case, what I done so far is made it so you can select a string with a space after each word and it will uppercase the first letter after the space. I want to add support for TABS also the code below works with tabs but if you insert a space before or after the tab is does not uppercase the next none space char can someone please have a look what I have done wrong thanks. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Capitalize(const S : String) : String;var  flag : Boolean;  S1 : String;  CH : String;  X : Integer;begin   flag := True;  S1 := '';    For X := 1 to Length(S) do begin       CH := Copy(S,X,1);        if flag then       begin         if (CH <> ' ') or (CH <> #9) then begin            S1 := S1 + UpperCase(CH);            flag := False;         end         else         begin             S1 := S1 + CH;         end;       end       else       begin           S1 := S1 + Lowercase(CH);           flag := (CH = ' ') OR (ch = #9);       end;   end;    Result := S1;end; ---------------------------------------------------------------------- alpine · 2022-07-03 23:03 Quote from: DreamVB on July 04, 2022, 12:41:20 amHi, I been making a little text editor and I am adding in some features to deal with converting a selection of text, I got the uppercase,lowercase and toggle-case working however I am stuck on the capitalize case, what I done so far is made it so you can select a string with a space after each word and it will uppercase the first letter after the space. I want to add support for TABS also the code below works with tabs but if you insert a space before or after the tab is does not uppercase the next none space char can someone please have a look what I have done wrong thanks. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Capitalize(const S : String) : String;var  flag : Boolean;  S1 : String;  CH : String;  X : Integer;begin   flag := True;  S1 := '';    For X := 1 to Length(S) do begin       CH := Copy(S,X,1);        if flag then       begin         if (CH <> ' ') or (CH <> #9) then begin            S1 := S1 + UpperCase(CH);            flag := False;         end         else         begin             S1 := S1 + CH;         end;       end       else       begin           S1 := S1 + Lowercase(CH);           flag := (CH = ' ') OR (ch = #9);       end;   end;    Result := S1;end; At line 17: the opposite of (CH = ' ') OR (ch = #9) is (CH <> ' ') and (CH <> #9) i.e. not(A or B) = (not A) and (not B) It is called "DeMorgan Law": https://en.wikipedia.org/wiki/De_Morgan%27s_laws ---------------------------------------------------------------------- dje · 2022-07-04 00:19 Have you tried StrUtils.AnsiProperCase? https://www.freepascal.org/docs-html/rtl/strutils/ansipropercase.html ---------------------------------------------------------------------- jamie · 2022-07-04 01:51 Hmm. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function CamelCaseWords(S:String):String;Var  LookingForFirstChar:Boolean = True;  I:Integer;begin  Result := S;  For I := 1 to Length(Result) do    Begin      If (LookingForFirstChar) And (Result[I]in['A'..'z'])     Then Result[I] :=UpCase(Result[I]);      LookingForFirstChar := Result[I] in [' ',#8];    end;end;                    Study that one. That should avoid UTF8 mixup and only cap Ansi.  But be aware, there does not expand the TAB. ---------------------------------------------------------------------- alpine · 2022-07-04 08:58 @jamie The name of the function is misleading. It is not doing a camelCase. The expression (Result[ I ]in['A'..'z']) includes non-letters, which is not fatal, but not very educational. ---------------------------------------------------------------------- jamie · 2022-07-04 10:14 And you don't do such things yourself ? ---------------------------------------------------------------------- DreamVB · 2022-07-04 18:06 Thanks y.ivanov it's working now, thanks to the rest that also give answers.