String Question
g3cwi
Posts: 262
Hi
I have a variable that contains a string. The string has a leading space that I want to get rid of. Assuming that the vaiable is called DIRECTION and contains " 1234", I want it to contain "1234". I thought the following code might do this but it fails.
Any ideas?
Regards
Richard
I have a variable that contains a string. The string has a leading space that I want to get rid of. Assuming that the vaiable is called DIRECTION and contains " 1234", I want it to contain "1234". I thought the following code might do this but it fails.
Temp :=strsize(direction) repeat i From 0 to Temp y:= i+1 direction[i] := direction[y]
Any ideas?
Regards
Richard
Comments
strsize takes an address. You were feeding it the value of the first byte. You can also use bytemove to do what you want more quickly and compactly.
-Phil
Gives a response from APRS.fi of:
" 234<0xb4><0xc4><0x04>". It correctly deals with the " 234" string but the shifted one is still wrong somehow.
Regards
Richard
-Phil
The problem is that direction is not a string variable (this does not exist in Spin). direction is just a pointer to the string " 234" in HubMemory, and is a long. So if you do: direction := direction[y] then you move longs and not bytes and you access anyway not the string location.
You can do it so:
but this work only one time, because you really change the string constant in memory.
So you need a string buffer to do it correct: I know this is a bit complicated. It will be the best to use a string library from the OBEX for string handling.
Andy
Magnificent! Worked first time. Thanks.
@Phil - thanks for your efforts. I know far less than you assume!
Richard
My apologies for missing that direction was already an address. I was still of the mindset that it was the name of an array, even though the string keyword proved otherwise. D'oh! What was I thinking? Not enough coffee, I guess.
Thanks, Andy, for rescuing me!
-Phil