Dear All,
I am looking to split a string as would do explode in PHP.
Here is code with explication
boolean sms_read(int sms_pos,char sms_from_number, char *sms_date, char *sms_time, char *sms_text)
{
// Definy a variable
char cmd[12];
// Set the command
sprintf(cmd,"AT+CMGR=%d,1",sms_pos);
//Send the commans
sendATcommand(cmd,"OK",2000,true,false,true); // This work.
// sendATcommand will save the repsonse into a buffer call buffer_by_line. Each line will be save in a row. See below
// It check the content of buffer_by_line
for(int b =0; b<NBLINES;b++)
{
Serial.print(b);
Serial.print(F(" : "));
Serial.println(buffer_by_line[b]);
}
/* Display buffer_by_line
0 : AT+CMGR=2,1
1 :
2 : +CMGR: "REC READ","55555","","13/09/08,14:25:34+08"
3 : Das von Ihnen gesendete Keyword ist leider falsch. Le mot cle envoye est malheureusement faux.
4 :
5 :
*/
// I display the SMS reveived message
Serial.print(F("Message :")); Serial.println(buffer_by_line[3]);
// Now I need those part: 5555, 13/09/08 and 14:25:34+08
// Donc j'utilise une des fonction de _pepe_. Mais ca bug de mon cote
splitString(buffer_by_line[2], splitedString, ",");
Serial.print(F("From :")); Serial.println(buffer_by_line[2]);
}
Juste above I am using a function to split the content of buffer_by_line[2] in order to have the result as follow
0:+CMGR: "REC READ",
1:"55555",
2:"",
3:"13/09/08,
4:14:25:34+08"
I still need to remove all ".
In php, there a function str_replace('"',''); Is there something similar woth C++, to remove "??
That line
splitString(buffer_by_line[2], splitedString, ",");
generate that error
sim908_cooking:814: error: cannot convert 'char*' to 'char**' for argument '2' to 'void splitString(char*, char**, char)'
However splitString() ask 3 char, and I sent 3 char, no????????
I also tryed
char *c = strtok(buffer_by_line[2], ",");
for(int cc=0; cc<strlen(c); cc++)
{
Serial.print(cc);Serial.print(":");Serial.println(c[cc]);
}
which display
0:+
1:C
2:M
3:G
4:R
5::
6:
7:"
8:R
9:E
10:C
11:
12:R
13:E
14:A
15:D
16:"
Here is the function splitString()
// SlitString
#define NBVALS 14
char splitedString[NBVALS];
void splitString(char *ligne, char **splitedString, char delimiter)
{
char *p = ligne;
int i = 0;
splitedString[i++] = p;
while (*p) {
//if (*p==',') {
if(*p = delimiter){
*p++ = '\0';
if (i<NBVALS)
splitedString[i++] = p;
} else
p++;
}
while(i<NBVALS)
splitedString[i++] = p;
}
Many thank for your help!!!!