Help with Parse split delimited string in c++

Hello everyone

How to make this code working in Arduino sketch ?

using namespace std;
void split(const string& s, char c, vector& v) {
string::size_type i = 0;
string::size_type j = s.find(c);
while (j != string::npos) {
v.push_back(s.substr(i, j-i));
i = ++j;
j = s.find(c, j);
if (j == string::npos)
v.push_back(s.substr(i, s.length( )));
int main( ) {
vector v;
string s = “Account Name|Address 1|Address 2|City”;
split(s, ‘|’, v);
for (int i = 0; i < v.size( ); ++i) {
cout << v << ‘\n’;

  • }*

The Arduino platform has very limited memory, so it will be ‘hard’ to implement something like this in in such a manner that you can add dynamically to the list without restrictions.

You could, and should, do something like this:


//define max length for entire string
//define max tokens
//define max token length

//function split
//put chars of string into token as long as next char is != token AND current index < max token length
    //if token found OR index out of bounds, progress to next token [remember to add the terminating 0 to the end of token]
        //if max tokens has been found return
    //if next token was '\0' return