Difference between revisions of "MID$ (statement)"
Jump to navigation Jump to search
|Line 3:||Line 3:|
:::''Syntax:'' MID$(string_to_alter$, start%, length%) = string_to_add$
Revision as of 10:04, 18 September 2009
The MID$ statement specifies a position in a STRING to overwrite previous data.
- Syntax: MID$(string_to_alter$, start%, length%) = string_to_add$
- String value is any literal or variable STRING or ASCII character value.
- Start specifies the string character to start and length reserves the space. Cannot be 0!
- The string value to be placed in the string should be as long as the length reserved.
- The length of the original string is NOT changed in any case! Excess characters will not be in the string retured.
- a$ = "The cats and dogs where playing, even though dogs don't like cats."
- start = 1 ' start cannot be 0 when used in the INSTR function!
- position = INSTR(start, a$, "dog")
- IF position THEN ' position is a value greater than 0
- MID$(a$, position, 3) = "rat" ' changes "dog" to "rat" when found
- start = position + 1 ' advance one position to search rest of string
- END IF
- LOOP UNTIL position = 0 ' no other matches found
- PRINT a$
Screen Results: The cats and rats were playing, even though rats don't like cats.