Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Atari BASIC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===String handling=== Atari BASIC copied the string-handling system of [[HP Time-Shared BASIC|Hewlett-Packard BASIC]],<ref>{{cite book |title=HP 2000/Access BASIC Reference Manual |publisher=Hewlett Packard |date=May 1976 |pages=e |url=http://bitsavers.org/pdf/hp/2000TSB/22687-90001_AccessBasic9-75.pdf }}</ref> where the basic data type is a single character, and strings are arrays of characters. Internally, a string is represented by a pointer to the first character in the string and its length. To initialize a string, it must be DIMensioned with its maximum length. For example: <syntaxhighlight lang="basic"> 10 DIM A$(20) 20 PRINT "ENTER MESSAGE: "; 30 INPUT A$ 40 PRINT A$ </syntaxhighlight> In this program, a 20 character string is reserved, and any characters in excess of the string length will be truncated. The maximum length of a string is 32,768 characters. There is no support for arrays of strings. A string is accessed using array indexing functions, or [[array slicing|slicing]]. <code>A$(1,10)</code> returns a string of the first 10 characters of <code>A$</code>. The arrays are 1-indexed, so a string of length 10 starts at 1 and ends at 10. Slicing functions simply set pointers to the start and end points within the existing allocated memory. Arrays are not initialized, so a numeric array or string contains whatever data was in memory when it was allocated. The following trick allows fast string initialization, and it is also useful for clearing large areas of memory of unwanted garbage. Numeric arrays can only be cleared with a FOR...NEXT loop: <syntaxhighlight lang="basic"> 10 REM Initialize A$ with 1000 characters of X 20 DIM A$(1000) 30 A$="X":A$(1000)=A$:A$(2)=A$ </syntaxhighlight> String concatenation works as in the following example. The target string must be large enough to hold the combined string or an error will result: <syntaxhighlight lang="basic"> 10 DIM A$(12),B$(6) 20 A$="Hello ":B$="there!" 30 A$(LEN(A$)+1)=B$ 40 PRINT A$ </syntaxhighlight> Values in DATA statements are comma-delimited and untyped. Consequently, strings in DATA statements are not typically enclosed by quote marks. As a result, it is not possible for data items to contain a comma but they can incorporate double-quotes. Numeric values in DATA statements are read as strings or as numbers according to the type of the variable they are read into. The READ statement cannot be used with array variables.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)