荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: oopilix (优雅的), 信区: Visual
标  题: [zl]change any string in ownname format
发信站: 荔园晨风BBS站 (Sun Jun  1 23:25:49 2003), 站内信件

Here's a sample function that should do what you want, if I properly figured
out just what it is that you want.

There are much faster ways to do this, but I wrote this right here in the EE
editor.. didn't start up Delphi to mess with doing anything fancy.  Maybe for
more points. ;)


//-------------
function CapitalizeEveryWord(sInput : string) : string;
var
 i : integer;
 bCapNextLetter : boolean;
 sRes : string;

begin
 sRes := '';
 bCapNextLetter := true;
 for i := 1 to length(sInput) do
   case sInput[i] of
     'a'..'z' :
       if bCapNextLetter then
         sRes := sRes + uppercase(sInput[i])
       else
         sRes := sRes + lowercase(sInput[i]);
     ' ' :
        begin
         bCapNextLetter := true;
         sRes := sRes + ' ';
       end;
   else
   begin
     sRes := sRes + ' ';
     bCapNextLetter := false;
   end;
   end;
   if sInput[i] in ('a'..'z'
 end;
 result := sRes;
end;




///////////////answer//////////////////////////////////


In source this spells out to:

S := LowerCase(S); //all chars in lowercase
for i := 1 to Length(S) - 1 do if S[i] = ' ' then S[i+1] := UpCase(S[i+1]);
//upcase every char after a space
S[1] := Upcase(S[1]); //upcase 1st char

where S is your string, and i some integer.

--
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 61.144.235.39]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店