MID$

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: MID$
Abbreviation: M, Shift+I
Type: Function
Token code: 202/$CA
Handling routine
in BASIC ROM:
46903–46944
$B737–B760
List of all BASIC keywords


Remark: This article describes the BASIC function MID$ in BASIC V2 at the Commodore 64.

Typ: String Function 
General Programming-Syntax: MID$(<string>,<1. integer number - startchar>,<2. integer number>)

MID$ will be used for cutting strings into component parts inside strings beginning by the startchar (1. integer number) until to the indicated length number (2. integer number) from the left side to the right side. The numerical values are 0 until 255. Outside the range - also negative or greater than 255 - the BASIC-error ?ILLEGAL QUANTITY ERROR IN line occurr. By using a wrong type of variable the BASIC-error ?TYPE MISMATCH ERROR in line appears. When the string or the numerical argument is missing, the BASIC-error ?SYNTAX ERROR IN line is displayed.

An empty string (for example A$="") is returned when the 1. integer number is greater than the string or the 2. integer number is 0. If the 2. integer number is not set or is greater than the rest of the string, the whole rest of string will be returned.

Examples[edit]

10 A$="SATURDAY MORNING"
20 B$=MID$(A$,6,3): PRINT B$ (DAY is cut and printed out)
30 B$=MID$(A$,1,8): PRINT B$ (same as LEFT$; SATURDAY is displayed)
40 B$=MID$(A$,10): PRINT B$ (same as RIGHT$ or MID$(A$,10,7); MORNING is displayed)


10 A$="SATURDAY MORNING"
20 FOR X=1 TO LEN(A$)+1 
30 PRINT TAB(X) MID$(A$,X,1): NEXT X
BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT