Spin2 Concatenate question
PropGuy2
Posts: 360
in Propeller 2
Maybe I missed it - But I am trying to Concatenate / Join, two sets of Integer numbers, and alternately two sets of Strings into one value:
For instance: Integer number = 50, AND an Integer number = 34567, into a single Integer value = 5034567
Alternately: String value = "John", AND a string value = "Smith" - into a single string = "John Smith"
Is there a Spin2 function - or has anyone written a function to do this ???
Comments
Spin has no string type, nor any built-in text/integer conversions. You'll need byte arrays to store your strings. Here's an example of concatenating two strings (passed as pointers).
Have a look at the attached demo -- it does the things you want to do. The key is understanding that there is no string type, that you need a byte array that is as big as your longest string plus one, and that there needs to be a zero following the last character of your string.
Thanks to Jon for the code ConCat Demo. I gently edited and added labels for clarity.
Hint - Make a new Directory for the ConCat Demo, and use PropTool 2.7.0 Beta
Hope this helps for anyone interested, Enjoy.
See the new main ConCat code attachment, the balance of code functions remains the same.
Here's a method (untested) for concatenating two integers that doesn't require conversion to strings and back. The integers must be positive.
Phil's example appears to work fine using PropTool 2.7.0, you just need to add ": value" to the PUB definition for the routine to return a value.