Shop OBEX P1 Docs P2 Docs Learn Events
array of string — Parallax Forums

array of string

tebrotebro Posts: 1
edited 2009-09-08 15:04 in Propeller 1
Hi,
Can you point me how to make a array of string with "0" final for close the string.
thanks
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-08 14:13
    You can't make an array of strings. String variables don't really exist in Spin anyway. They're arrays of bytes where the last byte is zero and they're handled by passing around the address of the first byte.

    What you can do is make a large array of bytes and divide it up into multiple groups and use each group of bytes as a string. You might have a total of 100 bytes that you divide up into groups of 10 bytes. The first string would be at @string[noparse][[/noparse]0]. The 2nd string would be at @string[noparse][[/noparse]10], etc.

    There are other ways to do this depending on what you want to use the strings for. Please give more information.
  • Ken PetersonKen Peterson Posts: 806
    edited 2009-09-08 15:04
    I did a project where I read in a string of lines representing filenames from an MP3 player. The filenames were delimited by a carriage return <CR>. I read them all into a buffer and then parsed through it replacing each instance of <CR> with 0. Then the address of the 1st byte as well as the address of each byte following a <CR> was stored in a LONG array, so I ended up with an array of string pointers.

    If your strings aren't changing, using an array of string pointers is easy to work with and is memory efficient. If you will be changing the strings at each index, I suggest Mike's approach unless you want to get into the complexity of managing a dynamic memory pool.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
Sign In or Register to comment.