Liberty BASIC - Help Online

String Variables
 
So far, the only kind of variables we have used are for holding number values.  There are special variables for holding words and other non-numeric character combinations.  These variables are called string variables (they hold strings of characters*).
 
    *Characters are:
 
      Letters of the alphabet ;
 
      Digits 0123456789 ;
 
      Any other special symbols like: , . < > / ? ; : ' " [ ] { } ` ~ ! @ # $ % ^ & * ( ) + - \ |    etc . . .
 
Let's look at a very simple program using strings:
 
    input "Please type your name ?"; name$
    print "It's nice to meet you, "; name$
 
This two-line program asks you for your name.  Once you've typed it and pressed [Enter], it responds with:
 
    It's nice to meet you, your-name-here
 
Notice one special thing about our string variable name.  It ends with a $ (dollar sign).  In BASIC, when you want to store characters in a variable, you end the variable name with a $.  This makes it a string variable.  As you can see from our program example, you can both input and print with string variables, as we did earlier with our non-string or numeric variables.
 
We've actually been using strings all along, even before this section about string variables.  Whenever you saw a BASIC program line with words in quotes (for example:  print "It's nice to meet you, ") you were looking at what is called a string literal.  This is a way to directly express a string in a BASIC program, exactly the way we type numbers directly in, only with characters instead.  A string literal always starts with a quotation mark and always ends with a quotation mark.  No quotation marks are allowed in between the starting and ending quotation marks (point: string literals cannot contain quotation marks).
 
NOTE  -  A string can have zero characters.  Such a string is often called an empty string.  In BASIC, an empty string can be expressed in a string literal as two quotation marks without any characters between them.  For example (noCharactersHere$ is the name of our string variable):
 
    let noCharactersHere$ = ""
 
Next Section: Some things to do with Strings


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