Answers to Concatenation exercise

 

Assuming that

o     the variable strFName contains the string –            Joe

o     the variable strMiddleIntial contains the string -   L

o     the variable strLName contains the string                      Smith

 

What does each of the following expressions resolve to? Would any result it an error message?

 

1.   strFName & strMiddleInitial & strLName

 

Result – JoeLSmith

 

If you want spaces to be printed between variables you must explicitly include them

 

2.   strFName” & “strMiddleInitial” & “strLName

 

Result – strFNamestrMiddleInitialstrLname

 

The variable names are enclosed in quotation marks making them string constants instead of variables.

 

3.                      strFName & “”strMiddleInitial & “.” & strLName

 

Result – This is will cause an error because it is missing an & between “” and strMiddleInitial, also there should be a space between the “ “.

 

4.   strFName & “ “ & strMiddleInitial & “.  strLName

 

Result – Joe L. strLName

 

This is getting better but the last variable is still enclosed in quotation marks.

 

5.   strFName & “ “ & strMiddleInitial & “. “ & strLName

 

Result – Joe L. Smith

 

The space between the first name and the middle initial is explicitly included as is the period and space following the middle initial.