Pages: [1]   Go Down
Author Topic: Is there a "split function in arduino?  (Read 373 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
« Last Edit: October 25, 2013, 12:18:52 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?


Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 99
Posts: 3626
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I update my reply.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Pages: [1]   Go Up
Jump to: