cancel
Showing results for 
Search instead for 
Did you mean: 

split words

Schamann
Associate II

Hello i have an Arduino project. I need create an array of words from sentence:

 

char sText[] = "This is a long text."; int x = 0; String arr[5]; //split by space char *token = strtok(sText, " "); while (token != NULL) { arr[x] = token; x++; token = strtok(NULL, " "); } //new sentence > "This text" char sNewText[] = arr[0] + " " + arr[4];

 

How can I do it similar in stm32CubeIde?

 

3 REPLIES 3

Standard part of string.h surely?

Would probably use strsep() as it's thread safe

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thx for your quickly reply, ofcourse i use string.h

#include <string.h>

but I have plenty of errors:

String or string

strsep or strtok does similar errors

 

gui/src/encrypt_screen/EncryptView.cpp: In member function 'virtual void EncryptView::DoEncrypt()': gui/src/encrypt_screen/EncryptView.cpp:109:2: error: 'String' was not declared in this scope String arr[5]; //string arr[5]; ^~~~~~ gui/src/encrypt_screen/EncryptView.cpp:109:2: note: suggested alternative: 'stdin' String arr[5]; ^~~~~~ stdin gui/src/encrypt_screen/EncryptView.cpp:111:16: error: 'strsep' was not declared in this scope char *token = strsep(sText, " "); ^~~~~~ gui/src/encrypt_screen/EncryptView.cpp:111:16: note: suggested alternative: 'strset' char *token = strsep(sText, " "); ^~~~~~ strset gui/src/encrypt_screen/EncryptView.cpp:113:6: error: 'arr' was not declared in this scope arr[x] = token; ^~~ gui/src/encrypt_screen/EncryptView.cpp:113:6: note: suggested alternative: 'VarOr' arr[x] = token; ^~~ VarOr generated/simulator/gcc/Makefile:196: recipe for target 'build/MINGW32_NT-6.2/gui/src/encrypt_screen/EncryptView.o' failed make[2]: *** [build/MINGW32_NT-6.2/gui/src/encrypt_screen/EncryptView.o] Error 1 make[1]: *** [generate_assets] Error 2 generated/simulator/gcc/Makefile:155: recipe for target 'generate_assets' failed make: *** [all] Error 2 simulator/gcc/Makefile:32: recipe for target 'all' failed Failed

 

Yeah, the mix-n-match of C/C++ will be fun.

https://www.programiz.com/cpp-programming/library-function/cstring/strtok

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..