2019-04-15 01:15:33 +00:00
|
|
|
The [[MID$]] statement substitutes one or more new characters for existing characters of a previously defined [[STRING]].
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2019-04-15 01:15:33 +00:00
|
|
|
: [[MID$]]({{Parameter|baseString$}}, {{Parameter|startPosition%}}[, {{Parameter|bytes%}}]) = {{Parameter|replacementString$}}
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageDescription}}
|
|
|
|
* The {{Parameter|baseString$}} variable must exist and be large enough to contain the {{Parameter|replacementString$}}.
|
|
|
|
* {{Parameter|startPosition%}} specifies the string character position to start the overwrite.
|
|
|
|
* {{Parameter|bytes%}} or number of characters is optional. Excess byte lenghts are ignored.
|
|
|
|
* The {{Parameter|replacementString$}} should be as long as the byte length reserved.
|
|
|
|
* The length of the original string is not changed in any case. If {{Parameter|replacementString$}} is longer, it gets clipped.
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageExamples}}
|
2015-08-02 12:12:44 +00:00
|
|
|
''Example:'' Using [[INSTR]] to locate the string positions and a [[MID$ (statement)|MID$]] statement to change the words.
|
|
|
|
|
|
|
|
{{CodeStart}}
|
2021-04-25 22:40:25 +00:00
|
|
|
text$ = "The cats and dogs were playing, even though dogs don't like cats."
|
|
|
|
{{Cl|PRINT}} text$
|
|
|
|
start% = 1 ' start cannot be 0 when used in the INSTR function!
|
|
|
|
{{Cl|DO...LOOP|DO}}
|
|
|
|
position% = {{Cl|INSTR}}(start%, text$, "dog")
|
|
|
|
{{Cl|IF}} position% {{Cl|THEN}} ' when position is a value greater than 0
|
|
|
|
{{Cl|MID$}}(text$, position%, 3) = "rat" ' change "dog" to "rat" when found
|
|
|
|
start% = position% + 1 ' advance one position to search rest of string
|
|
|
|
{{Cl|END IF}}
|
|
|
|
{{Cl|LOOP}} {{Cl|UNTIL}} position% = 0 ' no other matches found
|
|
|
|
{{Cl|PRINT}} text$ '' ''
|
2015-08-02 12:12:44 +00:00
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}
|
|
|
|
The cats and dogs were playing, even though dogs don't like cats.
|
|
|
|
The cats and rats were playing, even though rats don't like cats.
|
|
|
|
{{OutputEnd}}
|
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageSeeAlso}}
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[MID$]] {{text|(function)}}
|
|
|
|
* [[LEFT$]], [[RIGHT$]]
|
|
|
|
* [[INSTR]], [[ASCII]], [[STR$]], [[HEX$]], [[Bitmaps]] (example)
|
|
|
|
* [[MKI$]], [[MKL$]], [[MKS$]], [[MKD$]]
|
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|