String str = "hello " "world" "!"

Last Edited By Krjb Donovan
Last Updated: Mar 11, 2014 07:52 PM GMT

Question

Hello,

As you can see on the Subject, do you know why we can use double quote to concatenate the stirngs?

Regards, lzzzz

Answer

Hello lzzzz. I hope I spelled your name right!

The concatenation is a language feature handled by the compiler. It is not done while the program is running. As long as you have only quoted string constants, the compiler will connect them into one long string. This is useful for breaking up large strings across many lines to make your program neater.

You could have string str = "hello"

            "world"
            "!"

But you cannot have string str1 = "hello" string str2 = str1 "world";

I hope that helps you out.

Advertisement

©2020 eLuminary LLC. All rights reserved.