Serial Terminals and String Manipulation
CumQuaT
Posts: 156
Hi all,
Looking around the OBEX, I can see a number of fun looking data manipulation objects, but nothing PRECISELY like what I'm after (but please prove me wrong if I am, since it will help)
I have 4 long variables that I am transmitting back to my PC from my propellor, and I can submit each one back to the PC individually with no problems. However, what I would like to do is send them all back at once in a single long string, separated by colons.
So, instead of sending back data that looks like this:
532
634
12
1022
I would send back a single string that looks like this:
532:634:12:1022
Also, for a bonus question... I would like to add a mask to my numbers so that they always get returned back as 4 digit numbers, filling in the gaps with extra zeros, like so:
0532:0634:0012:1022
But I can't for the life of me work out a way of doing this... Does anyone have any ideas?
Looking around the OBEX, I can see a number of fun looking data manipulation objects, but nothing PRECISELY like what I'm after (but please prove me wrong if I am, since it will help)
I have 4 long variables that I am transmitting back to my PC from my propellor, and I can submit each one back to the PC individually with no problems. However, what I would like to do is send them all back at once in a single long string, separated by colons.
So, instead of sending back data that looks like this:
532
634
12
1022
I would send back a single string that looks like this:
532:634:12:1022
Also, for a bonus question... I would like to add a mask to my numbers so that they always get returned back as 4 digit numbers, filling in the gaps with extra zeros, like so:
0532:0634:0012:1022
But I can't for the life of me work out a way of doing this... Does anyone have any ideas?
Comments
Attached is Kyedos, and the bit you want is the string handler ASCII0_STREngine.spin Down the bottom are some of the Basic type string methods.
To use these, create some string space in the main program. Kyedos itself has this in its main program, but to summarise the important bits
and
String handling is still not quite as simple as in Basic, eg joining two strings is a function in the string handler rather than just using +
This is a summary of some of the routines I used to test out these strings
Most of the bits you need are in there, eg str.str (which is the same as strings.str).
The catch is that strings.right has not been written (yet). But you can replicate this in other ways that might be neater anyway. Instead of adding 4 zeros, then taking the right most 4 characters, first, convert your number to a string, then get the length of the string. (str.len) Subtract this number from 4, and add that many zeros using a loop and str.StringConcatenate
Full zip of Kyedos is attached but you will only be needing the strings object.
If you want to add characters between the numbers, eg a comma or a colon, add those with str.StringConcatenate
You might need to add a str.trim after converting the number to a string as there is a leading (hidden) space for positive numbers.