Mega Code Archive

 
Categories / Delphi / Examples
 

Capitalise

procedure TTHEForm1.CapitaliseBuffer; {Perform our own DIY conversion routine. Careful examination of characters in the range 0 to 255 reveals that there are two uninterrupted sequences of lowercase characters that have uppercase equivalents (and vice versa). One sequence is in the lower ('ASCII') range (ie 'a' to 'z') -the other sequence is in the higher range (ie à to ı). Also, for both sequences the uppercase equivalent of a character is 32 characters LESS than the lowercase version. So, therefore, the algorithm will be: IF character in range 97 to 122 inclusive, OR if character in range 224 to 253 inclusive, then character = the character 32 characters 'behind'...} var i: Integer; begin for i := 1 to sizeof(Buffer^) do begin if (((Ord(Buffer^[i]) >= 97) and (Ord(Buffer^[i]) <= 122))) then begin Buffer^[i] := Chr(Ord(Buffer^[i]) - 32); end; if (((Ord(Buffer^[i]) >= 224) and (Ord(Buffer^[i]) <= 253))) then begin Buffer^[i] := Chr(Ord(Buffer^[i]) - 32); end; end; {we might be scanning through NULLs at the end of the last buffer but this doesn't matter...} end;