Re: function to convert first letter of each word in a s tring
"cstakdk" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
Thanks, its working fine cstakdk --- In [email protected], Allan Smith <AJMSmith@N...> wrote: > 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:cstakdk@y...] > >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 Toner for Your Printer or Fax at LaserTonerSuperstore.com-Save 55%! We have your brand: HP, IBM, Canon, Xerox, Apple and many more for less! http://www.LaserTonerSuperstore.com http://us.click.yahoo.com/YmQqWC/qicGAA/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/