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

9
  • Do you want to split the string on a particular character or position?
    – st2000
    Commented Aug 21, 2016 at 19:53
  • 1
    You can use strtok(). It's not part of the Arduino core library: it's just a libc function. Commented Aug 21, 2016 at 20:02
  • And, how am I supposed to find that libc (I guess a library) thing?
    – Konko
    Commented Aug 21, 2016 at 20:45
  • Mr.Bonet, pls, I need this answer...
    – Konko
    Commented Aug 21, 2016 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
    Commented Aug 21, 2016 at 20:52

1 Answer 1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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