Shop OBEX P1 Docs P2 Docs Learn Events
Spin Text Processing Questions — Parallax Forums

Spin Text Processing Questions

Martin_HMartin_H Posts: 4,051
edited 2011-11-25 14:48 in Propeller 1
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-25 14:28
    A single character string has a numeric value, so you can write:

    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.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-11-25 14:48
    Mike, thanks for the information. You are helpful as always.

    I wish I thought of using bytemove, it makes sense in a typeless language like Spin.
Sign In or Register to comment.