Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[Delphi] Format a string to proper case

delphi string

  • Please log in to reply
2 replies to this topic

#1 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 20 November 2010 - 02:50 PM


The following function returns the given string formatted in proper or sentence case, i.e. the first letter is upper case and the rest is in lower case.



E.g:

[LIST]

[*]input: "roses are red", output: "Roses are red"

[*]input: "c", output: "C"

[*]input: "roSES ARe RED", output: "Roses are red"

[/LIST]



[CODE]

function ProperCase(const AString: string): string;

begin

  // make all characters into lower case

  Result := LowerCase(AString);



  // if the supplied string is not empty string, then make the first character an upper case

  if Result <> '' then  UpCase(Result[1])

end;


  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 21 November 2010 - 05:43 AM

Nice bit of code :)
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 22 November 2010 - 05:01 AM

^ Lol, thank you! Too simple of a code, I think!
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download