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

-Collapse +Expand Prism To/From
-Collapse +Expand Prism Study Test
-Collapse +Expand Prism Store

Prestwood eMagazine

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

   ► KBProgrammingDelphi PrismLanguage Basics   Print This    All Groups  
  From the February 2016 Issue of Prestwood eMag
Prism Language Basics:
Delphi Prism String Concatenation (+)
Posted 14 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


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:
//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:


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);
FirstName : String;
LastName : String;
sbFullName := new StringBuilder;
FirstName := 'Mike';
LastName := 'Prestwood';

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

More Info


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

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

Posted 12 years ago

Comment 2 of 3

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

Posted 12 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 11 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 = P151A1
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 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
Since 2/17/2009
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

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