Spin Text Processing Questions
Martin_H
Posts: 4,051
I haven't done much text processing in Spin, so this is the first time I've bumped into this and reading the manual didn't help. How do you compare against a character constant? The following C-ish syntax failed.
' copy the byte if it is not the HTML encode sequence.
if byte[ptr][idx] <> '%'
The problem is '%' is not a numeric value. I dropped in $25 and that worked, but it was distinctly unsatisfying from an aesthetics point of view.
Spin has a string length and compare functions, but does it have a string copy function? Obviously a repeat while will do the trick, but something like C's strncpy could prevent potential bugs.
Also does anyone have any HTML URL decode code kicking around in Spin? I want to translate two hex digits into a binary number and while I can write the code, I would prefer re-use.
' copy the byte if it is not the HTML encode sequence.
if byte[ptr][idx] <> '%'
The problem is '%' is not a numeric value. I dropped in $25 and that worked, but it was distinctly unsatisfying from an aesthetics point of view.
Spin has a string length and compare functions, but does it have a string copy function? Obviously a repeat while will do the trick, but something like C's strncpy could prevent potential bugs.
Also does anyone have any HTML URL decode code kicking around in Spin? I want to translate two hex digits into a binary number and while I can write the code, I would prefer re-use.
Comments
if byte[ptr][idx] <> "%"
The string copy function is BYTEMOVE. It needs a length, so you have to use STRSIZE as well.
Have a look at the GetAnyNumber method near the end of the main FemtoBasic.spin file (from the ObEx) for ideas for numeric input conversion. It handles hexadecimal, binary, decimal, and single character string values.
I wish I thought of using bytemove, it makes sense in a typeless language like Spin.