Go Down

Topic: help with String manipulation (Read 1 time) previous topic - next topic

zoomkat

Quote
I was hoping that there would be a straight forward solution like SlaveID=mid(cstring,0,3) - good old VB


There is the below.

http://arduino.cc/en/Reference/StringObject
http://www.arduino.cc/en/Tutorial/TextString

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

JT007

Hi Zoomkat,
i saw the information you pointed out,
unfortunately i couldnt find an example which would simply strip characters from a string between linits.
could you provide me with a direct link to the example
cheers
Jason

zoomkat


Hi Zoomkat,
i saw the information you pointed out,
unfortunately i couldnt find an example which would simply strip characters from a string between linits.
could you provide me with a direct link to the example
cheers
Jason


The below shows how to find the position of a delimiting character in a string, then using an offset, find the location of the next delimiting character in the string. Once you know the positions of the two characters, you can use those locations to capture the substring between the two like in the bottom example.

http://arduino.cc/en/Tutorial/StringIndexOf

http://arduino.cc/en/Tutorial/StringSubstring
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

JT007

Yes i understand what you are saying but unfortunately i dont have delimiting characters
the format is 255O255|the part of the code which is handling the parsing does not see the end character "|" which has already been stripped.
i need to be able to use the character position instead.
the examples dont offer any suggestion on how to do this.

as mentioned above i could in VB.

I am currently going back over the code and seeing if i can adopt Pauls suggestion.

thanks for the help
J.

johncc

with
cmd="255O255|";

preconditions
strlen(cmd)==8
&& cmd[3]=='O'
&& cmd[7]=='|' )

int slave=atoi( cmd);     // gives you the address
int value=atoi( cmd+4); // gives you the value

Doesn't that "get you there from here"?

Also are you sure about the 3 digit thing?
i.e. you will be getting "023O004|" not "23O4|"

John

Go Up