Schrijver
| MID$ statement
|
flyguille msx master Berichten: 1202 | Geplaatst: 15 April 2006, 23:44   |
I am curius
using MID$ as a instruction (not a function)
MID$(A$,3,2) = "AB"
now, that is the normal, it remplaces the third and fourth chr of A$ with "AB"
Now, in pure basic what's do the following statements.
MID$(A$,3,2) = ""
MID$(A$,3,2) = "12345"
MID$(A$,3) = "BB"
MID$(A$,3,3) = "1"
I know the behaviour that it takes in differents versions of BASIC.. but what says the standard about these sentences?
|
|
NYYRIKKI msx master Berichten: 1509 | Geplaatst: 16 April 2006, 00:57   |
Standard? Yeah right... eh...
I think, that "Microsoft BASIC" is kind of "standard" as different BASIC versions made by Microsoft share quite a much same basic command set.
First BASIC made by Microsoft was Altair BASIC made in 1975
Altair BASIC manual says folowing of the MID$ instruction:
MID$(string,n[,m])=string2 Replace a portion of string with string2; start at pos n for m chars
I think this is most close to standard you ever get.
The original BASIC made by John Kemeny and Thomas Kurtz in 1963 did not have MID$ instruction.
|
|
flyguille msx master Berichten: 1202 | Geplaatst: 16 April 2006, 03:14   |
so, realy does?
mid$(string1,start1,x1) = string2
==
mid$(string1,1,start1-1) + string2 + mid$(string1,start1+x1)
with reason is slow the mid$ statement
I was thinking in just working overriding with pointers.
|
|
NYYRIKKI msx master Berichten: 1509 | Geplaatst: 16 April 2006, 03:33   |
Yes you can think so as long as len(string2)=x1
|
|
arnold_m msx lover Berichten: 81 | Geplaatst: 16 April 2006, 10:01   |
I've just tried it out.
If the string data is still stored in the program it is copied to the string pool first.
When the data is stored in the string pool, it is changed in place.
The MID$ statement does not change the length of the string.
Of course other BASIC's may behave differently.
The program
5 DEFINT A-Z
10 A$="abcdefghij":B$=A$:GOSUB 100:GOSUB 110
20 MID$(A$,3,4)="----": B$=A$:GOSUB100:GOSUB 110
30 MID$(A$,5,4)="====": GOSUB 100:GOSUB 110
40 MID$(A$,5,2)="....": GOSUB 100
50 MID$(A$,5,2)="": GOSUB 100
60 END
100 LPRINT"A$:";:P=VARPTR(A$): GOSUB 200:RETURN
110 RETURN:PRINT"B$:";:P=VARPTR(B$): GOSUB 200:RETURN
200 Q=PEEK(P+2):IF Q>=128 THENQ=Q-256
210 Q=Q*256+PEEK(P+1)
220 LPRINTHEX$(P)"->"HEX$(Q);"->'";
230 IF PEEK(P) THEN FOR I=Q TO Q+PEEK(P)-1:LPRINTCHR$(PEEK(I));:NEXT
240 LPRINT"'":RETURN
gives:
A$:8180->8013->'abcdefghij'
A$:8180->DC58->'ab----ghij'
A$:8180->DC58->'ab--====ij'
A$:8180->DC58->'ab--..==ij'
A$:8180->DC58->'ab--..==ij'
|
|
flyguille msx master Berichten: 1202 | Geplaatst: 16 April 2006, 21:26   |
so it realy doesn't remplace mid$(A$) width B$, it overwrites!!
|
|
|
|
|