Watch Out for Literals in Concatenation

Speaking of string concatenation, you have to watch out for concatenations involving string literals. For example consider the following apparently trivial lines of code:

Log ( 'String: ' + strl); Log (strl + ' is a string');

Now if strl is a UnicodeString, there should be no problem at all. If strl is an AnsiString, in one of its variations, the concatenation with a Unicode string literal might force different conversions depending whether the string literal comes before or after the string variable. In most mixed string cases involving literals, my suggestion is to add an explicit type cast for the string, like in:

Log ('String: ' + UnicodeString(strl)); Log (unicodeString(strl) + ' is a string');

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment