String Concatenation: Difference between revisions

From Liberty BASIC Family
Jump to navigation Jump to search
m (Text replacement - "Building Blocks Categories" to "Building Blocks")
 
m (1 revision imported)
 
(No difference)

Latest revision as of 03:04, 11 October 2023

Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

String concatenation is joining strings together.

Syntax

JB has two string concatenation operators:
stringExpression + stringExpression
the result is a string expression,
and
anyExpression ; anyExpression
anyExpression will be converted into a string and then the strings are concatenated,
the result is a string expression.

Hints

Experiments show that (;) operator has lowest possible priority, while (+) has priority above relational operators. So
"2">"3"+"1"
first performs string concatenation, then comparison, and result is <false> (numeric 0), while
"2">"3";"1"
first performs comparison, gets <false> (numeric 0), then converts it to string and concatenates. Result in this case is string "01".

Example

    varOne$ = "Hello"
    varTwo$ = "World"
    varThree$ = varOne$ + " " + varTwo$
    print varThree$

    varOne$ = "Hello"
    varTwo$ = "World"
    varThree$ = varOne$ ; " " ; varTwo$
    print varThree$

    varOne$ = "Apollo"
    varTwo = 17
    varThree$ = varOne$ ; " " ; varTwo
    print varThree$

    varOne = 19
    varTwo = 72
    varThree$ = varOne ; varTwo
    print varThree$

Useful Procedures

' Place a useful function or sub using this keyword here