View Full Version : Question in Char Separating

10-09-2013, 08:18 AM
i'm using gsm lib and i want to separate the content of smsbuffer. ex Hello World then i will disregard the Hello and i will only get the World and store in Another byte/char array. tnx

10-10-2013, 09:46 PM
So split a string on a delimiter like " " ? That sounds like strtok() / strntok() to me. I did a simpler verison for some parsing code I wrote.

// copy t to s until delimiter is reached
// return location of delimiter+1 in t
// if s or t null, return null
char *split(char *s, char *t, int max, char delim)
int i = 0;
if (s == 0 || t == 0)
return 0;
while (*t != 0 && *t != '\n' && *t != delim && i < max) {
*s++ = *t++;
*s = 0;
return t+1;

10-12-2013, 12:27 AM
i used arduino lib


MatchState ms;
char * str = smsbuffer;
ms.Target (str);

unsigned int index = 0;
char buf [100];

while (true)
char result = ms.Match ("(%a+)" "(%-?%d+)", index);

if (result == REGEXP_MATCHED){
for (int j = 0; j < ms.level; j++);
index = ms.MatchStart + ms.MatchLength;

can you help how to correct this one.. tnx

10-12-2013, 04:06 PM
No, we cannot help you correct this, because you are not showing us what the problem is.

What is the problem? Do you get a compile error? If so, on which line?

Btw: Regexp is not the right approach to string matching on a very limited device such as the Arduino. strtok(), or just picking the string apart using strchr() or walking each character in the string manually would be much better.