Shop OBEX P1 Docs P2 Docs Learn Events
Combining strings — Parallax Forums

Combining strings

DgswanerDgswaner Posts: 795
edited 2008-04-12 01:45 in Propeller 1
I've scoured the manual, tried and tried. with no luck. Can some one tell me the command or how to combing strings.

I want to read some variables, and combine them as one long string. I was able to do this in Pbasic (going from memory) by: x = "hello_" + "world"
but if I do that with spin it seems to add the numeric values of the 2 and I only get weird symbols.

do I need to write each variable to memory and then read the whole memory area as one string?

I'm stuck. any help would be appreciated.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-10 04:24
    There is no native string manipultaion support, you can either get an object from obex or use bytemove to directly manipulate memory, but you also need to make sure theres room to do the copy, and that you strip the 0 at the end of the first string and make sure the 0 and the end of the resultant string is there

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • DgswanerDgswaner Posts: 795
    edited 2008-04-10 04:32
    Thanks Paul, at least I can stop looking now. I think I'm going to try a different approach that doesn't require sending one string. thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner

    Post Edited (Dgswaner) : 4/10/2008 4:39:36 AM GMT
  • hippyhippy Posts: 1,981
    edited 2008-04-10 14:29
    There's some information and example code for combining and manipulating strings on the Propeller Wiki ...

    propeller.wikispaces.com/Strings
  • Chuck RiceChuck Rice Posts: 210
    edited 2008-04-12 01:45
    Here is a little routine that I use to concatinate strings

    Example call:
    var
      byte buffer[noparse][[/noparse]80]
    
    pub
      concatStr(@buffer,string("hiya-"),string("toots"))
    
    



    Concatenation routine
    pub concatStr(dest,s1,s2)     '' Concatenates two strings and stores the result in 'dest'
    
        bytemove(dest,s1,strsize(s1))
        bytemove(dest+strsize(s1),s2,strsize(s2))
    
    



    -Chuck-
Sign In or Register to comment.