Liberty BASIC- Help Online

Some Things to Do with Strings
 
Just as you can manipulate numbers in a computer programming language by adding, subtracting, multiplying, and dividing, (and more!), we can also manipulate strings
 
Adding strings  -  We can add (or concatenate) two or more strings together in BASIC like so:
 
    input "What is your first name ?"; firstName$
    input "What is your last name ?"; lastName$
    let fullName$ = firstName$ + " " + lastName$
    print "Your full name is: "; fullName$
 
In this short program, we input two strings, your first and last name.  Then we concatenate the string in firstName$ with the string literal  " "  (a single space between two quotes) and with lastName$.  The result is made the data for the string variable fullName$, which we then print out.
 
Comparing strings  -  We can compare strings with each other just as we can compare numbers.  This means that we can use the if . . . then statement and the ( =, <>, <, >, <=, >= ) operators to determine whether:
 
    a$ = b$a$ is equal to b$
    a$ <> b$a$ is unequal to b$
    a$ < b$   a$ is less than b$
    a$ > b$a$ is greater than b$
    a$ <= b$a$ is less than or equal to b$
    a$ >= b$a$ is greater than or equal to b$
 
When comparing strings, a string is considered to be equal to another string when all the characters in one string are exactly  the same in both strings.  This means that even if they both print the same onto the screen, they can still be unequal if one has an invisible space on the end, and the other doesn't.  For example:
 
    a$ = "Hello"
    b$ = "Hello "
    print "a$ is "; a$
    print "b$ is "; b$
    if a$ = b$ then goto [areTheSame]
    print "a$ and b$ are not the same"
    goto [end]
[areTheSame]
    print "a$ and b$ are the same"
[end]
 
 
When the line  if a$ = b$ then goto [same]  is performed, the result is not to goto [same], because even though if a$ and b$ were printed they would look  the same, they are not actually the same.
 
 
 
Next Section: Functions


Copyright (C) 2005 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/