Shop OBEX P1 Docs P2 Docs Learn Events
String Stuff — Parallax Forums

String Stuff

Lawrence ShaferLawrence Shafer Posts: 12
edited 2007-03-16 13:00 in BASIC Stamp
It's been years since I last used a basic stamp and I've forgotten way too much! shocked.gif

I know there is a command for getting certain chars from a string, but I cannot find it now? How would I go about pulling the last two chars (or the middle, or first for that matter) from a string?

And how would I add one string to another, not mathematically but kinda like this
string3 = [noparse][[/noparse]string1, string2]
--OR--
string3 = string1 AND string2

Anyway, you get the idea,

I feel stupid for forgetting this much, and now I can't even find it.

Thanks,
Lawrence

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-16 05:54
    Strings are just arrays of characters. There isn't any way to pull groups of characters from a string (other than one at a time) and there's no way to add one string to another unless you program it yourself, say with a loop. You can declare an array of bytes like:
    myArray  VAR  byte(5)
    


    This gives you a 5 character array with subscripts starting at zero. You can access the 4th character like:
    if myArray(3) = "." then ...
    


    Have a look at the PBasic manual. Remember that there are special "formatters" for the I/O statements that will input or output a string, either a specific number of characters from an array or a zero-terminated string value. This helps a little.
  • Lawrence ShaferLawrence Shafer Posts: 12
    edited 2007-03-16 12:43
    It seems like I remember something about mid$() left$() and right$() or something like that, but I cannot find anything on it.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-03-16 13:00
    Lawrence -

    Indeed the usual string functions mid$(), left$(), and right$() do exist in certain varients of BASIC. PBASIC (the language for the Parallax Stamp) has no string functions and no inherent string handling capability. This doesn't mean that you can't use strings, it just means you have to use the existing language command set in some clever ways to simulate string functions, to the minimal extent that one can. Here is one example below.

    The single biggest problem that one usually runs across is the the unavaiability of a string comparison function. Because of that, each character of an alphameric array must be compared individually to establish the appropriate comparison relationship.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.