string + string, combining string
courtens
Posts: 101
Is there an way to do this; to combine two strings
Thanks
...
Sorry - I just solved it
string("hello " + "world")
Thanks
...
Sorry - I just solved it
string("hello " , "world")
Comments
Actually it's weird what this does in Spin,
These strings are treated as bytes and the "+" operator adds the numeric value of 'o' to that of 'w' then sticks that result in the middle producing a rather unexpected string result.
I finally got it to work, but only after trying to call for the value by using the @
this works:
tv.str(@string1)
this will give some funny stuff back
tv.str(string1)
Mike, your code helped me digest the log post Bytemove-question,
Now I need to add a number to my "hello world", would I first need to convert the number into a sting with the numbers.spin function FromStr(StrAddr, Format)?
I know there's a thread about how to do this.
I think Larry (Lardom) started the thread. I'll see if I can find it.
This isn't a complete demo but hopefully there's enough here that you can make sense of it.
The code inserts four ASCII characters that represent the value held by the variable "tryCount" to the byte arrays "logName" and "backupName". The characters replace the original "0" characters. The idea was to have the file names increment each time a new file was created.
The code is from a data logging project.
I actually just got this this code to work using the numbers.spin function ToStr
This gives me "hello 12345"
This works if I send the sting out:
_newLine:=13
reg_25:=string("@16 11 25 965401272 ", _newLine)
But anything else I am trying is a no go.
This would overwrite the final zero byte with two bytes ... the newline and a new zero byte at the end.
I just got it to work with using
string3 := string(" ", _newLine, "test >>>")
I had to increase the cog size and fix a typo in my code...
There are functions to join strings, and a nifty one to build a string that can handle the backspace, so you can use it for a keyboard.
Dr_Acula, thank you for your suggestion of using Kye's string driver. At this point I have all I need in this string @arr_25. It covers all I require it to do. Now I can use some math and send this command string to a motor ... and it works!
I was trying to find some documentation about this "simple" sort of string + number handling thing, but could not easily find it. There is very little in the help files, very little in the "Official Book", none in the "Unofficial Book", bits and pieces all over the forum (thank goodness) and some here: propeller.wikispaces.com.
Thinking on the bit/byte level is a new concept for me, and it was only thanks to the very helpful support in this forum -- it all started to make sense. I spent days reading on how to get this to work ... adding a number to a string, and adding a string to a string. So, thank you all again!
My next thing to add to my code is saving values through a power off cycle using extra external memory ...