STRINGS

 

Str

Converts any value into string.

Example:

Print Str(6.7)+"7"

 

Left

Reads some characters from the left side of a string

Usage:

ret$ = Left(Stri$, length)

 

Right

Reads some characters from the right side of a string

Usage:

ret$ = Right(Stri$, length)

 

Mid

Reads some characters from the middle of a string

Usage:

ret$ = Mid(Stri$, position, length)

 

InStr

This command will allow you to search for an occurrence of a string within another string. The command returns the location (number of characters from the left) of the string you are looking for. Command returns a zero if no matches are found.

Usage:

pos = InStr(Stri$, Find$ [, start])

Example:

theline$="Don't you worry, babe. I'm an expert."

Text 0,0,theline$

Text 20,20,"The location of 'babe' is: "+Instr(theline$,"babe")

Text 20,33,"The location of 'hasta la vista' is: "+Instr(theline$,"hasta la vista")

'Try to search substring "you" after the 10th character...

Text 20,46,"The location of 'you' from character 10 is: "+Instr(theline$,"you",10)

'(of course it can't be found because "you" is located at 7)

DrawScreen

WaitKey

 

Replace

This command will allow you to replace characters within a string with another. Use this to strip or convert letters out of your strings (like removing spaces or turning them into underscores).

Usage:

ret$ = Replace(Stri$, find$, replaceWith$)

Example:

theline$="Don't you worry, babe. I'm an expert."

'Print the original

Print theline$

'Print replace "babe" with "John"

Print Replace(theline$,"babe", "John")

'Print remove the "you" word

Print Replace(theline$,"you ","")

WaitKey

 

Upper

Returns the passed string with all characters converted to upper case

Usage:

ret$ = Upper(Stri$)

 

Lower

Returns the passed string with all characters converted to lower case

Usage:

ret$ = Lower(Stri$)

 

Trim

Removes all leading and tailing spaces and tabs from a string

Usage:

ret$ = Trim(Stri$)

 

Lset

Makes a string the length of your choosing by padding the rest of it with spaces. This makes the string left justified.

Usage:

ret$ = Lset(Stri$, length)

 

Rset

Makes a string the length of your choosing by padding the head of it with spaces. This makes the string right justified.

Usage:

ret$ = Rset(Stri$, length)

 

Chr

Transforms an ASCII-code (0-255) into corresponding single character

Usage:

char$ = Chr(ASCII)

 

Asc

Transforms a single character into corresponding ASCII-code.

Usage:

ASCII = Asc(char$)

 

Len

Tells the length of the given string, in characters.

Usage:

length = Len(Stri$)

Example:

Repeat

    k$=Input("Give a sentence: ")   

    'Print the length

    Text 0,50,"Text length: "+Len(k$)

    DrawScreen

Until KeyHit(cbkeyreturn)

CloseInput

 

Hex

Converts an integer value into string represented in Hex-form

Usage:

ret$ = Hex(number)

 

Bin

Converts an integer value into string represented in binary-form

Usage:

ret$ = Bin(number)

 

String

Builds a string by repeating the given string for a number of times.

Usage:

ret$ = String(Stri$, repeats)

Example:

AddText "Use LEFT and RIGHT arrow to change length"

length=1

Repeat

    If KeyHit(cbkeyleft) Then length-1

    If KeyHit(cbkeyright) Then length+1   

    If length<0 Then length=0

    build$=String("Hello",length)    

    Text 0,50,build$   

    DrawScreen   

Until KeyHit(cbkeyreturn)

 

Flip

Flips a string. "Hello World" turns into "dlroW olleH"

Usage:

ret$ = Flip(Stri$)

 

StrInsert

Inserts a string inside another string at given position.

Usage:

ret$ = StrInsert(Stri$, position, pokeString$)

Example:

'original string

stri$="Don't worry babe, I'm an expert."

Text 10,10,stri$

'insert a new word at position 6

stri$=StrInsert(stri$,6,"you ")

Text 10,30,stri$

DrawScreen

WaitKey

 

StrRemove

Removes a portion inside a string.

Usage:

ret$ = StrRemove(Stri$, position, length)

Example:

'original string

stri$="Don't worry babe, I'm an expert."

Text 10,10,stri$

'delete word "babe"

stri$=StrRemove(stri$,12,5)

Text 10,30,stri$

DrawScreen

WaitKey

 

StrMove

With this function you can move a portion of string to another place in that same string

Usage:

ret$ = StrMove(Stri$, position, length, shift)

 

Example:

'original string

stri$="Don't you worry, babe. I'm an expert."

Text 10,10,stri$

'move word "you" after "worry"

stri$=StrMove(stri$,6,4,6)

Text 10,30,stri$

DrawScreen

WaitKey

 

CountWords

Tells how many 'fields' can be found in the string according to specified separator character. The separator defaults to space.

Usage:

howMany = CountWords(Stri$, separator$)

 

GetWord

Extracts a word separated by a specified character in a string. See the example. The separator defaults to space.

Usage:

Word$ = GetWord(Stri$, index [, separator$])

Example:

mytext$="one two three four five six"

'orignal text

Text 0,0,mytext$

'grab all words

For i=1 To CountWords(mytext$)

    Text 10, 20+i*10, GetWord(mytext$,i)

Next i

DrawScreen

WaitKey