我有Telit调制解调器,我想获取SIM卡电话号码,Telit返回字符串如下:

"+CNUM: "","+123456789123456",**145**ok"

Or : "+CNUM: "","+123456789123456",**129**ok"


仅与数字145(International), 129(National)不同。

我只想获取数字:+123456789123456,不带“ + CNUM:”和“ 129”。

我试过了:

responseBuffer ="+CNUM: "",""+123456789123456"",145";
sscanf(responseBuffer,"%*s %s",phoneNum);   // cut the beginning


我如何摆脱字符串的重置,即从','到结尾的字符?

最佳答案

感谢@JoachimPileborg我使用strtok

responseBuffer ="+CNUM: "",""+123456789123456"",145";
token = strtok(responseBuffer, ",");
if( token != NULL )
  token = strtok(NULL, ",");
strcpy(phoneNum,token);

09-28 02:07