Accessing string elements, casting?
GrendelT
Posts: 23
In the following code, I've created a string using a long the string( ) call, and I've created a byte array to form the string "spin".
Why on the pst.str(foo[1]) does it not print p? If I include the @ operator to make it @foo[1], I get pin, not just the p. How would I pull only the p from foo?
Do I need to do some casting trickery on it? Is that what the byte[ ] syntax I've seen used on others' code? Casting? If not, please explain what that means, I'm having a hard time finding it. (or at least tell me the name of it so I can look it up.)
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ pst : "Parallax Serial Terminal" VAR byte foo[10] long bar[10] PUB main pst.Start(115200) foo[0] := "s" foo[1] := "p" foo[2] := "i" foo[3] := "n" foo[4] := 0 bar := string("fun") pst.str(foo[1]) pst.newline pst.str(bar)
Why on the pst.str(foo[1]) does it not print p? If I include the @ operator to make it @foo[1], I get pin, not just the p. How would I pull only the p from foo?
Do I need to do some casting trickery on it? Is that what the byte[ ] syntax I've seen used on others' code? Casting? If not, please explain what that means, I'm having a hard time finding it. (or at least tell me the name of it so I can look it up.)
Comments
If you have a closer look at the used objects you'll find that the str method is usually based on the single character output method, e.g.
How about the byte[ ] or word[ ] syntax I see used from time to time? What's that called/doing?