Dim Parts as zstring*40
Dim Bins(1 to 3) as string
Parts = "staples"
Bins(1) = Parts
Bins(2) = ""staples"
'Notice the string length for Bins(1) <> Bins(2)
'Now any time Bins() is printed it will always have a additional byte. Is there a easy way to always have a dynamic string be the same size without
having to change its size by using poke?
Dim Parts as zstring*40
Dim Bins(1 to 3) as string
Parts = "staples"
Bins(1) = Parts
Bins(2) = ""staples"
'Notice the string length for Bins(1) <> Bins(2)
'Now any time Bins() is printed it will always have a additional byte. Is there a easy way to always have a dynamic string be the same size without
having to change its size by using poke?
are you sure you are not using
print len(bin(1))
print len(bin(2))
(Because I have inadvertently did just that)
Dim Parts as zstring*40
Dim a as zstring*2
Dim Bins(1 to 3) as string
Parts = ""
Print "enter staples"
do
a=""
while a=""
a=inkey
wend
print a;
Parts = Parts + a
loop while a <> chr(13)
Parts[Len(Parts)] = 0
Bins(1) = Parts
Bins(2) = "staples"
print "length Bins(1) = ";len(Bins(1))
print "length Bins(2) = ";len(Bins(2))
Notice the string length for Bins(1) <> Bins(2).'
Why is this? What am I not seeing?
Now any time Bins() is printed it will always have a additional byte. Is there
a easy way to always have a dynamic string be the same size without having to change its size by using poke?
Dim Parts as zstring*40
Dim a as zstring*2
Dim Bins(1 to 3) as string
Parts = ""
Print "enter staples"
do
a=""
while a=""
a=inkey
sleep 10 '' so as not to hog the CPU
wend
if a <> chr(13) then
print a;
Parts = Parts + a
else
print
end if
loop while a <> chr(13)
'Parts[Len(Parts)] = 0 '' useless
Bins(1) = Parts
Bins(2) = "staples"
print "length Bins(1) = ";len(Bins(1))
print "length Bins(2) = ";len(Bins(2))
StillLearning wrote: ↑Oct 12, 2022 5:29
Notice the string length for Bins(1) <> Bins(2).'
Why is this? What am I not seeing?
- 'Bins(1)' ('=Parts') is the concatenation of the characters entered in the loop.
- 'Bins(2)' = "staples"
Last edited by fxm on Oct 12, 2022 11:57, edited 1 time in total.
Reason:Correction of a typo ('Bin' instead of 'Bins') thanks to the dodicat remark.
instead of using
Parts[Len(Parts)] = 0
use
Parts[Len(Parts)-1] = 0
this correctly makes the last character chr(0) which will take the place of chr(13) and abruptly stop the zstring at the correct length.
fxm
- 'Bin(1)' ('=Parts') is the concatenation of the characters entered in the loop.
- 'bin(2)' = "staples"
The same Bin I wrongly used in my test.