"I'm just looking at your nametag, honest!"
YOUR SECOND GFA BASIC 3.XX MANUAL
- or -
HOW I LEARNED TO STOP WORRYING AND LOVE GFA-BASIC
PART 8
CHAPTER SEVEN - STRINGS
by Han Kempen
INSTR-bug
The command INSTR(a$,b$,i) always returns '1' if a$=b$. For i=1
that's fine, but not for i>1. Don't blame me, I'm just the
messenger.
RINSTR-bug
The command RINSTR will miss the character you're looking for if
it is exactly on the spot you specified as the start-position:
PRINT RINSTR("abcd","c",3) ! "c" is missed on position 3
Adding one to the desired start-position is a solution, but you
can also leave the start-position out:
PRINT RINSTR("abcd","c",4) ! now "c" is found
PRINT RINSTR("abcd","c") ! this should work too
In the latter case you can always continue your search from the
first position you found, but you might as well use INSTR if
you're going to search the whole string.
LSET and RSET
If you use LSET or RSET, the string is padded with spaces:
a$=" 345"
LSET a$="12"
PRINT a$ ! you'll see "12 ", not "12345"
In some publications this is mentioned as a bug. It's not a bug,
but a blunder in my official Dutch GFA-Manual where it is stated
that "12345" should be printed.
You can use RSET for right justification of columns:
f$=SPACE$(10)
FOR i=0 TO 9
RSET f$=text$(i)
PRINT TAB(20);f$
NEXT i
Garbage Collection
You are informed already about the nasty garbage collection bug
(paragraph 'Storing data in RAM'), so I don't have to repeat that
sad story here.
If you are constructing a large string by adding one character
at the time with 't$=t$+char$' you should realize that the old
string is not replaced by the new string. Each time you add a
character, a new string is created while the old string is left
as garbage. You could prevent the clogging up of precious RAM by
first creating a string of the proper length with
't$=SPACE$(len)' and using 'MID$' to insert new characters. Now
only one string is used and there will be no garbage to collect
at all.
Functions (CHAPTER.07)
Char_count CHRCOUNT
Counts the number of times a certain character occurs in a
string:
PRINT @char_count(TRUE,txt$,"a") ! count the a's in txt$
If the flag is TRUE, the function distinguishes between upper
and lower case. If the flag is FALSE both upper and lower case
characters are counted. The same flag is also used in the
Functions Left$ and Right$.
Left$ LEFT
Returns the part of the string in front of a search-string:
PRINT @left$(TRUE,txt$,search$) ! flag for upper/lower cs
The complete string is returned if the search-string is not
found. This Function is useful for parsing a text-string.
Lowercase$ LOWRCASE
Returns a string with all capitals converted to lower case:
PRINT @lowercase$(txt$)
This is the reverse of UPPER$. As with UPPER$, the original
string is not changed.
Right$ RIGHT
Returns the part of the string following a search-string:
PRINT @right$(TRUE,txt$,search$) ! flag for upper/lower c
The nullstring is returned if the search-string is not found.
This Function is useful for parsing a text-string.
String_reverse$ STR_REV
Returns the reverse of a string:
PRINT @string_reverse$(txt$)
The original string is not changed. Note how garbage collection
is prevented in this Function by first declaring the new string
and then inserting the characters in reverse order. Adding one
character at a time with something like
'rev$=rev$+MID$(txt$,i,1)' would leave a lot of garbage.
Trim_left$ TRIM_L
Strip all leading space-characters from a string:
PRINT "#";@trim_left$(" trim left")
Trim_right$ TRIM_R
Strip all trailing space-chracters from a string:
PRINT @trim_right$("trim right ");"#"
Disclaimer
The text of the articles is identical to the originals like they appeared
in old ST NEWS issues. Please take into consideration that the author(s)
was (were) a lot younger and less responsible back then. So bad jokes,
bad English, youthful arrogance, insults, bravura, over-crediting and
tastelessness should be taken with at least a grain of salt. Any contact
and/or payment information, as well as deadlines/release dates of any
kind should be regarded as outdated. Due to the fact that these pages are
not actually contained in an Atari executable here, references to scroll
texts, featured demo screens and hidden articles may also be irrelevant.