Go Down

Topic: Is there a "split function in arduino? (Read 459 times) previous topic - next topic

cabecinhas

Hi. I need to get a vlaue inside a string with the comma delimiter. is it possible?

Like:

example:
String Vnames  = "Roger, Mark, Rose, Paul"

how could I get the "Mark"  or the "Rose" for example?

Something like
vnameok = split(Vnames," , ")(2). Where the  comma is the delimiter and the (2)  is the 3th position.

HazardsMind

#1
Oct 25, 2013, 07:07 pm Last Edit: Oct 25, 2013, 07:18 pm by HazardsMind Reason: 1
Yes it is a C string function called "strtok()"
What it does is it reads the buffer and looks for a split character( , . : / ; -   ) really any character you want, and it will output what ever is before the split character.

I can't remember if the buffer needs to be null terminated or not, I think it does.

"Hello, it is 1:20 pm. "
Output = strtok( buffer, ",:" ); //"Hello"
Output = strtok( NULL, ",:" );// " it is 1"
Output = strtok( NULL, ".");// "20 pm"
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

cabecinhas

Hi. Tks for answering. I think I can but could you give me an example about how to get the 3th pro exanple:

Like:

variable = "joh, mary,rose,joseph"


I have been searching for this function and strtok seems doesn't do this.

Am I wrong?



HazardsMind

My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy