Shop OBEX P1 Docs P2 Docs Learn Events
breaking up variables to pieces? — Parallax Forums

breaking up variables to pieces?

mosquito56mosquito56 Posts: 387
edited 2007-12-31 03:29 in Propeller 1
I have this " Hello world", I want this
H
E
l
l
o

W....
·· I have tried this
'' Print a zero-terminated string
· repeat strsize(stringptr)
··· term.out(byte[noparse][[/noparse]stringptr++])
··· term.chr(everything I could think of 10,13 lineclf) nothing works

and searched search.pallalax.com but everything is for stamp on sting work.

I am looking for substring("string", start, length) or a way to do it.

A pointer to the place that deals with memory and breaking var's up would be nice.




▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.


Technologically challenged individual, Please have pity.

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-12-30 21:56
    How about (not tested):
    For i from start to end
       term.out(@myStr+i)          ' output character at string location + index
    .
    .
    .
    DAT
    MyStr   Byte "Hello World"
     
    

    -Martin


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    SelmaWare Solutions - StampPlot GUI for controllers, XBee and Propeller Application Boards

    Southern Illinois University Carbondale, Electronic Systems Technologies

    American Technical Educator's Assoc. Conference·- April, Biloxi, MS. -- PROPELLER WORKSHOP!
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-30 22:05
    that seems to only work on a pre-defined constant and doesn't work on a variable. I found that in the manual.
    Try changing to "Good bye cruel world"

    also there is no for next in spin: also there is no way to see it on the next line.

    That is a first day example from a basic book. I could be wrong. If so appologies on end.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.


    Technologically challenged individual, Please have pity.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-30 22:25
    How do you have this string stored? Remember that Spin is not Basic. There are no built-in strings other than string constants. You can store strings in byte arrays, but that's not exactly the same. You're right ... there is no FOR/NEXT in Spin. It's all handled by the REPEAT statement which also does the DO/LOOP and WHILE loop constructions.
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-30 23:26
    i am willing to strore it any way that works. I want to take a large integer and scale it and the put a decimal in the middle for readability. Using r/c delay for adc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.


    Technologically challenged individual, Please have pity.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-30 23:49
    You could actually format this sort of thing on the fly by modifying a standard decimal number display routine like this:
    PUB dec(value, scaleBy) | i
    
    '' Print a decimal number
    
      if value < 0
        -value
        out("-")
    
      i := 1_000_000_000
    
      repeat 10
        if i == scaleBy / 10
          out(".")
          result~~
        if value => i
          out(value / i + "0")
          value //= i
          result~~
        elseif result or i == 1
          out("0")
        i /= 10
    
    


    If you want 2400 to display as 2.400, you'd call dec(2400,1000).
    Obviously, change calls to out() to be whatever you need.
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-31 01:14
    Sweet, some nice code there. I am going to printout the operand page and try to memorize the thing. You guys can take a 20line progam and do it with 2 lines. Thanx much. will give it a try soonest.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.


    Technologically challenged individual, Please have pity.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-12-31 02:11
    Yeah, sorry about my code... like I said, not tested, and sometimes gets confusing writing in 3 different languages at once. Glad Mike could help.

    -Martin
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-31 02:42
    Well Martin made a real mess of it smile.gifsmile.gif

    His code should read as follows, and it would be very similar to Mosquito's in his OP:

    
    PUB main | c, stringAddr
    stringAddr := @myStr
    REPEAT WHILE c:=BYTE[noparse][[/noparse]stringAddr++]
       term.out(c)
       term.out(13)
    .
    .
    .
    DAT
    MyStr   BYTE "Hello World",0
    



    Coming to numbers there are many formatting options with the object NUMBERS and FLOATSTRING.
    When you want to do it yourself, you have to do some COPYING, using BYTEMOVE(dest,src,size)

    So:
    (1) allocate the memory for your string to be, either in VAR space, or - more obvious - in DAT space. The advantage with DAT is that you can better place templates...
    Ex:
    string2b  BYTE "The number is: XXXXXXXXX      ",13,0
    end2b
    


    (2) You can output this string by a .STR routine of a driver.
    (3) You change parts of it
    - either by loops containing
     string2b[noparse][[/noparse]17] := "9"
     string2b[noparse][[/noparse]18] := "."
     string2b[noparse][[/noparse]19] := "9"
    
    

    or something more intelligent.
    - or copy from another place
     BYTEMOVE(@string2b+17, theSourceStringAddress, STRSIZE(theSourceStringAddress))
    
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-31 03:29
    Mike, thanks much was exactly what I needed. I don't understand it but I can use it for now. Like I said, I need to study the operand page a little closer. Have a good one

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.


    Technologically challenged individual, Please have pity.
Sign In or Register to comment.