标签:
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] );
使用sscanf函数提取某个字符串中某个字符后面的字符串的方法
标签:
原文地址:http://www.cnblogs.com/txf1949/p/4301390.html