|
Post by get1960 on Nov 14, 2018 12:28:31 GMT -5
Hi. I would like to know if it is possible to dimension an array where the values are two-digit and will be extracted as wanted? I am tinkering with three single dimension arrays. A$ is a string array. N$ contains numbers. E$ contains the values that I use to get the value in A$.
For Example:
A$=" abcdefghijklmnopqrstuvwxyz" N$="000102030405060708091011121314151617181920212223242526"
E$="07051518"
E$ treats the array value as one digit instead of two. Like this: instead of 07 it uses 0 the first time through the loop. 7 the second time through the loop. I would like them to be treated as 07, 05, 15, 18. NOT as 0,7,0,5,1,5,1,8.
Thanks
|
|
|
Post by tsh73 on Nov 14, 2018 15:58:47 GMT -5
E$="07051518" for i = 1 to len(E$) step 2 c$=mid$(E$,i,2) print c$ next
But this is not an array, at all. Array would be
'E$="07051518" data 07, 05, 15, 18
'make array dim e(4)
'read into array for i = 1 to 4 read tmp e(i)=tmp next
'print array - do whatever you need with array for i = 1 to 4 print i,e(i) next
|
|
|
Post by tenochtitlanuk on Nov 14, 2018 16:46:27 GMT -5
Couple examples for you-
E$ ="07051518" ' this is a string not an array.
print E$ 'To get bits two-at-a-time you could use 'mid$(' eg..... print "As a string "; mid$( E$, 1, 2)' ' will print the first two chars #1 and #2 in the string as a string two characters long print "and as a number "; val( mid$( E$, 1, 2)) ' will print them as a number print "As a string "; mid$( E$, 3, 2) ' will print the chars #3 and #4 in the string as a string two characters long print "and as a number "; val( mid$( E$, 3, 2)) ' will print them as a number print
'Another useful way is to space the pairs with a character- typically a space od a comma ( is csv) E2$ ="07 05 15 18" print E2$ print "As a string, first two chars represent "; word$( E2$, 1, " ") print " and as a number the second pair have value "; val( word$( E2$, 2, " "))
|
|
|
Post by get1960 on Nov 14, 2018 23:49:03 GMT -5
E$="07051518" for i = 1 to len(E$) step 2 c$=mid$(E$,i,2) print c$ next
But this is not an array, at all. Array would be 'E$="07051518" data 07, 05, 15, 18
'make array dim e(4)
'read into array for i = 1 to 4 read tmp e(i)=tmp next
'print array - do whatever you need with array for i = 1 to 4 print i,e(i) next
Thanks. Now I feel like a goof. I have been working with strings for the last few months and I did similar programs but different enough from one another.
|
|
|
Post by get1960 on Nov 14, 2018 23:50:06 GMT -5
Couple examples for you- E$ ="07051518" ' this is a string not an array.
print E$ 'To get bits two-at-a-time you could use 'mid$(' eg..... print "As a string "; mid$( E$, 1, 2)' ' will print the first two chars #1 and #2 in the string as a string two characters long print "and as a number "; val( mid$( E$, 1, 2)) ' will print them as a number print "As a string "; mid$( E$, 3, 2) ' will print the chars #3 and #4 in the string as a string two characters long print "and as a number "; val( mid$( E$, 3, 2)) ' will print them as a number print
'Another useful way is to space the pairs with a character- typically a space od a comma ( is csv) E2$ ="07 05 15 18" print E2$ print "As a string, first two chars represent "; word$( E2$, 1, " ") print " and as a number the second pair have value "; val( word$( E2$, 2, " "))
Thanks. Now I feel like a goof. I have been working with strings for the last few months and I did similar programs but different enough from one another.
|
|