Shop OBEX P1 Docs P2 Docs Learn Events
loop through input string? — Parallax Forums

loop through input string?

elementiselementis Posts: 3
edited 2008-09-10 23:45 in BASIC Stamp
Ok well I am going to have to admit Im a complete novice at PBASIC, though am not a novice to programming in general.

I just started messing with this language yesterday and am stuck with one thing.

I want to use the DEBUGIN command to get a random string inputted by the user.

Once the input is gotten I want this program to be able to loop through every character in the string, and then to perform the appropriate subroutine depending on the each letter iteration that is passed through the loop.

From my understanding the PBASIC language does not have any built in string handling functions, so that is why im stuck.

How can I get the PBASIC language to take a inputted string and break it down into an array of characters that I can loop through? and how exactly would I loop through each character of that given string?

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-09-09 02:38
    Hi, DEBUGIN can actually place an input string into an array, look at the Special Formatters in the DEBUGIN help file and check out the STR ByteArray \L \E instruction.

    Each element of that array can then be addressed via it's index, ByteArray(0),ByteArray(1),ByteArray(2).........etc.

    Jeff T.
  • elementiselementis Posts: 3
    edited 2008-09-09 22:19
    Ok I get the concept,
    but if it wouldn't be too much trouble can somebody show me a coded example of using the debugin command to take a variable string, and then maybe debug each character individually from a loop?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-09-10 05:23
    Hi,

    ByteArray VAR Byte(6)·········· 'declare 6 byte array
    idx VAR Nib
    main:
    FOR idx=0 TO 5
    ByteArray(idx)=0··············· 'fill array with zeros to denote end of string
    NEXT
    DEBUGIN STR ByteArray\6\CR····· 'input upto a 6 character string
    FOR idx=0 TO 5
    IF ByteArray(idx)=0 THEN EXIT·· 'check for end of string
    DEBUG ByteArray(idx)··········· 'debug 1 character at a time
    NEXT
    DEBUG CR, STR ByteArray,CR····· 'debug the whole string at once
    GOTO main

    hope this helps

    Jeff T.
  • elementiselementis Posts: 3
    edited 2008-09-10 23:01
    EDIT: disreguard that question, I figured it out myself



    Thanks you thats exactly what i needed!
    Im pretty much making my first ever program with PBASIC for my electronics class and i decided to go above and beyond my class since i have previous programming knowledge to make a light diode emit a morse code S.O.S based on the users inputted string.
    Now that I know how to loop through each character i can finally now easily do the rest!!

    thank you very much.

    but is it possible to do a string with that example to be able to have up to infinity characters? or even just have a really large number of characters?
  • Dave-WDave-W Posts: 94
    edited 2008-09-10 23:45
    Elementis,

    Now you can connect a small speaker and here the morse code also! Sounds like fun.

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