0

I'm about identify myself stupid, howcome I couldn' t figure out how to split a string into substring using arduino, even after 10 days of searching. The number is fact... So, As Mr.Arduino.cc says: string.substring() is just can be used as conditional phrase with loops like if. and there is no method such strtok() like in C can help me with this. So guys, I' m bagging you for help, please!

if (ks > 255 * 60)
            {
                    vek.print("Bu yazı, ", 25, 0);
                    vek.printNumI(255*60, 25, 8);
                    vek.print("karakterd-", 25, 16);
                    vek.print("en uzun ol", 25, 24);
                    vek.print("dugundan", 25, 32);
                    vek.print("gosterlemz", 25, 40);
            }

for (byte i = 0; i <= ss ; i ++)
            {
                    for (byte j = 0; j <= 6; j++)
                    {
                            int ilk_kar = j * 10 + i * 60;
                            int son_kar = ilk_kar + 10;

                            String yaz=readString.strtok(ilk_kar,son_kar);

                            vek.print(yaz, 25, j);

                            if (analogRead(A5) == 1023)
                            {
                                    continue;
                            }
                            else
                            {
                                    break;
                            }
                    }
            }
    }
}

Error: sketch_aug22a.ino: In function ‘void loop()’: sketch_aug22a.ino:83:56: error: ‘class String’ has no member named ‘strtok’

What am I supposed to do?

Thanks, already...

  • Do you want to split the string on a particular character or position? – st2000 Aug 21 '16 at 19:53
  • 1
    You can use strtok(). It's not part of the Arduino core library: it's just a libc function. – Edgar Bonet Aug 21 '16 at 20:02
  • And, how am I supposed to find that libc (I guess a library) thing? – Konko Aug 21 '16 at 20:45
  • Mr.Bonet, pls, I need this answer... – Konko Aug 21 '16 at 20:49
  • It would help to have the above questions answered. Do you want to split at a certain spot (eg. 5th character)? Or after certain symbols (eg. a comma)? – Nick Gammon Aug 21 '16 at 20:52
1

Import the string.h library by adding #include <string.h> on top of your sketch, in order to use the strtok() function. Checkout the usage example of strtok() here: http://www.cplusplus.com/reference/cstring/strtok/?kw=strtok

  • in arduino ide? – Konko Aug 22 '16 at 9:49
  • Yes, of course. – Dmitri Aug 22 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.