Single Byte access
 
Syntax


 

someString(index)

Description


A string is just an array of bytes, terminated by a 0.  Strings are limited to 256 characters (no bounds checking).  So individual bytes can be accessed like individual elements in an array.

Extracting or setting a single byte in a string can be done with an index STRING(3) refers to the 4th byte of the string (starts from 0).

Example

  
DIM text(10) as string
  
text(0) = chr("H")          ' single character strings like "H" are treated like a character constant 
text(1) = chr( "E") 
text(2) = chr( "L") 
text(3) = text(2)            ' copy the previous character 
text(4) = text(3) + 3      ' expressions are OK too, the result is truncated to 8 bits 
text(5) = 0 

 
PRINT text     ' will display  HELLO
   

Differences from other BASICs

See also