IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Prism
Search Prism Group:

Advanced
-Collapse +Expand Prism To/From
To/FromCODEGuides
-Collapse +Expand Prism Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Prism Store
PRESTWOODSTORE

Prestwood eMagazine

January Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi PrismLanguage Basics   Print This     
  From the February 2016 Issue of Prestwood eMag
 
Prism Language Basics:
Delphi Prism String Concatenation (+)
 
Posted 10 years ago on 2/17/2009 and updated 9/15/2009
Prism Code Snippet:
 A flashcard from our Prism Flashcards Library
 A code snippet from our Prism Code Snippets Page

KB101921



Delphi Prism String Concatenation

Unlike Delphi, Prism performs implicit casting. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Syntax Example:
var FirstName : String;
var LastName : String;
  
FirstName := 'Mike';
LastName := 'Prestwood';
ShowMessage('Full name: ' + FirstName + ' ' + LastName);
  
//Implicit casting of numbers.
//
//This fails:
//MessageBox.Show(3.3);
//
//This works:
MessageBox.Show("" + 3.3);

Using System.Text.StringBuilder

Many times using the StringBuilder class is faster than concatenation. If you have extensive string manipulations to perform, consider using the StringBuilder class.

First add System.Text to your uses:

Uses
  System.Text;

Then use the methods from the StringBuilder class. For example, you can use Append and ToString as follows:

method MainForm.StringBuilderBtn_Click(sender: System.Object; e: System.EventArgs);
var
FirstName : String;
LastName : String;
sbFullName := new StringBuilder;
begin
FirstName := 'Mike';
LastName := 'Prestwood';

//Concatenation.
MessageBox.Show(FirstName + " " + LastName);
 
  //StringBuilder class.
sbFullName.Append(FirstName);
sbFullName.Append(" ");
sbFullName.Append(LastName);
  MessageBox.Show(sbFullName.ToString);
end;

More Info


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 3

FWIW, there's a couple of Catcatenations in with the Concatentations ;-)

Posted 8 years ago

Comment 2 of 3

Oops! Embarassed The spelling errors are fixed now. Thanks for letting me know.

Posted 8 years ago

Comment 3 of 3

Now that I have done more .net and Delphi Prism, I also wouldn't do a concatenation just to convert to string.

You can actually do:

MessageBox.Show( 3.3.ToString );

Posted 7 years ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1186A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101921 Counter
13332
Since 2/17/2009
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2019 Prestwood IT Solutions.   [Security & Privacy]