Re: function to convert first letter of each word in a s tring
Allan Smith <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 18 Jul 2003 15:02:13 +0300, Shkolnik M. wrote:
>Use the next code:
>
>function Proper(strStr: string): string;
>var
> IsStartWord: Boolean;
> i: Integer;
> ch: Char;
>begin
> IsStartWord := True;
> Result := '';
> if (Length(strStr) > 0) then
> for i := 1 to Length(strStr) do
> begin
> if IsStartWord then
> ch := AnsiUpperCase(strStr[i])[1]
> else
> ch := AnsiLowerCase(strStr[i])[1];
> IsStartWord := (ch = ' ');
> Result := Result + ch;
> end;
>end;
>
>For example, ShowMessage('george bush w');
>
>-----Original Message-----
>From: cstakdk [mailto:[email protected]]
>Sent: Friday, July 18, 2003 2:57 PM
>To: [email protected]
>Subject: [Delphi] function to convert first letter of each word in a string
>
>
>hi...
>
>if the user enter a name and surname into the text like geroge bush w
>i need the result in George Bush W
>
>Is there any function in Delphi(i am new comer in delphi)
>Please advice me
>thanks
>thanks for the pervious answers
>csta
Not entirely sure but the following will probably be better (faster, less
memory, no string concatenation)
Function Proper (Const StrStr : String) : String;
VAR I : Integer;
Begin
// Conver the whole string to lower case
Result := AnsiLowerCase (StrStr);
If Length (StrStr) > 0 Then
Begin
// Always convert the first letter
Result [1] := AnsiUpperCase (Result [1])[1];
For I := 2 To Length (StrStr) Do
If Result [Pred (I)] = ' ' Then
// Overwrite only if need be
Result [I] := AnsiUpperCase (Result [I])[1];
End;
End; { Proper }
--
Regards,
Allan Smith (Northwood, Middlesex, England)
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sOykFB/k9VGAA/ySSFAA/i7folB/TM
---------------------------------------------------------------------~->
CodeCoffer - new Delphi code protection Tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/