Copy a part of a string to a new string ?
nestor73
Posts: 33
I have learned the SPIN language for almost 2 weeks now, and i have to say that,
even do i'm a programmer for over 20 years, this language is the worst i've writtin
in ! This is not to be called a 'high-level' language at all. Or maybe i'm getting very
frustrated that i can't even seem to get the easiest thing done like,
1) adding 2 strings to eachother ?
2) I need to be able to copy a part of a string . In my case , the string contains a 2 digit
number and i need to be able to put the first one in a new string, and the second one too..
Is there an 'easy' way to do this ? i haven't been able to come up with something that
at least works a bit :frown:
even do i'm a programmer for over 20 years, this language is the worst i've writtin
in ! This is not to be called a 'high-level' language at all. Or maybe i'm getting very
frustrated that i can't even seem to get the easiest thing done like,
1) adding 2 strings to eachother ?
2) I need to be able to copy a part of a string . In my case , the string contains a 2 digit
number and i need to be able to put the first one in a new string, and the second one too..
Is there an 'easy' way to do this ? i haven't been able to come up with something that
at least works a bit :frown:
Comments
Because then you don't expect big things like variable datarecords. You got bytes words longs. That's it.
For more complex things you the user have to care about all the details.
Strings are defined as byte-arrays where each byte contains one ascii-coded character.
copying a complete byte-array can be done with the command bytemove. If you want to copy parts of a string you have to calculate offsets
another possability is to copy it bytewise
there are some string-handling objects in the obex
http://obex.parallax.com/objects/543/
keep the questions coming
best regards
Stefan
Are the two digits integers or ASCII? If they are integers you have to ASCII encode the numbers before concatenating to the end of a string. This is consistent with any high level language although subtle; ie obejct.ToString()
Maybe you could even solve the problem beforehand! Do you really need to copy, or could you propably put the numbers to the right position in the first place?
Post your code and we can help you to improve your SPIN skills.
It's highly possible that i'm so new to this, and i'm so used to progamming in PHP and Pascal that i'm so distant from this way of working. But i did program for the arduino last year and that worked just allot easier. For some reason the SPIN tool is hard for me to see trough, dunno.
Anyway, i found a function called SubStr in an object called 'strings'. I ripped it out of it, i'm already low on programming space so i don't need all the other functions that it's bringing . And that works fine.
I did work my way around the concatenate of the strings by working with a buffer and returning that from the function. Works also ok. But it's only a matter of time before i bump into a new problem. ha. I don't have my code here in this computer since i work on another one for that, i'll upload code from there later.
The problem that i'll run into will be screen slowness. I have build a big clock out of characters, meaning that for example the "0" is made out of a series of empty (red colored) strings that are positioned in a way that it created a half screen size (vga) character. Because i have two clocks (timers) on screen it will take a hell of a time to update 8 big characters
An example of that screen can be seen here ::
This screen is just showing fixed characters, but last night i've been working to make them running,
and experienced allot of slowness. I'll make it that way that only the characters that are changing are
updating, but still i don't expect it to go smooth .
Anyone has a better idea to get those big clocks smooth onscreen ?
You have to pass two string addresses (the destination and the source) along with the start position (inside the source) and the length of the substring. The method returns the destination pointer passed to it so that you can embed this method inside .str() methods.
Example:
...will print "Propeller" to the terminal. The array called buffer holds the result.
hope to get the code to display those big characters working and put it here for others to use
keep the questions coming
best regards
Stefan