1,例子1:
#include <stdio.h>#include <stdlib.h>main(){char s[]="abc 123 n:xyz";char s2[80];sscanf(s,"%*[^:]:%s",s2);printf("%s",s2);} 2,例子2:取出=之后的数字
// 格式
"verno=DP_B002_REL_V10","interval=0","pwd=000000","sos_num1=15084781942","sos_num2=15084781942","sos_num3=15084781942","sos_num4=15084781942","listen_num=","firewall=1","alm=0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;","prof=0;7:4:6;0:0:0;0:0:0;7:4:6;
解析方法:
// verno
sscanf(list.at(0).toLocal8Bit().data(),"%*[^=]=%s",&syncDeviceInfo.verno[0] );
// interval
sscanf(list.at(1).toLocal8Bit().data(),"%*[^=]=%d",&syncDeviceInfo.nInterval );
// pwd
sscanf(list.at(2).toLocal8Bit().data(),"%*[^=]=%d",&syncDeviceInfo.pwd );
// sos_num1
sscanf(list.at(3).toLocal8Bit().data(),"%*[^=]=%s",&syncDeviceInfo.sos_num1[0] );
时间: 2024-10-10 06:54:55