Liberty BASIC Help Online |
Manipulating Characters
CHR$( n )
Description:
This function returns a one character long string, consisting of the character represented on the ASCII table by the value n (0 - 255).
Usage:
print chr$(77)
print chr$(34)
print chr$(155)
Produces:
M
"
›
INSTR(string1, string2, starting) |
Description:
This function returns the position of string2 within string1. If string2 occurs more than once in string1, then only the position of the leftmost occurance will be returned. If the starting parameter is included, then the search for string2 will begin at the position specified by starting.
Usage:
print instr("hello there", "lo")
produces: 4
print instr("greetings and meetings", "eetin")
produces: 3
print instr("greetings and meetings", "eetin", 5)
produces: 16
If string2 is not found in string1, or if string2 is not found after starting, then INSTR( ) will return 0.
print instr("hello", "el", 3)
produces: 0
and so does:
print instr("hello", "bye")
Description:
This function returns the length in characters of string, which can be any valid string expression.
Usage:
prompt "What is your name?"; yourName$
print "Your name is "; len(yourName$); " letters long"
Description:
This function returns from string the specified number of characters starting from the left. If string is "hello there", and number is 5, then "hello" is the result.
Usage:
[retry]
input "Please enter a sentence>"; sentence$
if sentence$ = "" then [retry]
for i = 1 to len(sentence$)
print left$(sentence$, i)
next i
Produces:
Please enter a sentence>That's all folks!
T
Th
Tha
That
That'
That's
That's_
That's a
That's al
That's all
That's all_
That's all f
That's all fo
That's all fol
That's all folk
That's all folks
That's all folks!
Note: If number is zero or less, then "" (an empty string) will be returned. If number is greater than or equal to the number of characters in string, then string will be returned.
Description:
This function returns a sequence of characters from the right hand side of string using number to determine how many characters to return. If number is 0, then "" (an empty string) is returned. If number is greater than or equal to the number of characters in string, then string will itself be returned.
Usage:
print right$("I'm right handed", 12)
Produces:
right handed
And:
print right$("hello world", 50)
Produces:
hello world
MID$(string, index, [number]) |
Description:
This function permits the extraction of a sequence of characters from string starting at index. [number] is optional. If number is not specified, then all the characters from index to the end of the string are returned. If number is specified, then only as many characters as number specifies will be returned, starting from index.
Usage:
print mid$("greeting Earth creature", 10, 5)
Produces:
Earth
And:
string$ = "The quick brown fox jumped over the lazy dog"
for i = 1 to len(string$) step 5
print mid$(string$, i, 5)
next i
Produces:
The_q
uick_
brown
_fox_
jumpe_
d_ove
r_the
_lazy
_dog
Description:
This function returns a copy of the contents of string, but with all letters converted to lowercase.
Usage:
print lower$( "The Taj Mahal" )
Produces:
the taj mahal
Description:
This function returns a copy of the contents of string, but with all letters converted to uppercase.
Usage:
print upper$( "The Taj Mahal" )
Produces:
THE TAJ MAHAL
Description:
This function removes any spaces from the start and end of string. This can be useful for cleaning up data entry among other things.
Usage:
sentence$ = " Greetings "
print len(trim$(sentence$))
Produces: 9
Description:
This function will a return a string of n space characters (ASCII 32). It is useful when producing formatted output to a file or printer.
Usage:
for x = 1 to 10
print space$(x); "*"
next x
Produces:
*
*
*
*
*
*
*
*
*
*
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/