标签:swscanf_s使用
//(1) TCHAR buf[12] = { 0 }; swscanf_s(_T("a/n"), _T("%*[^/]/%s"), buf,12); TRACE(_T("%s"), buf); //(2) TCHAR buf3[10] = { 0 }; TCHAR buf4[10] = { 0 }; swscanf_s(_T("a=b"), _T("%[^=] %*[=]%s"), buf3, 10,buf4,10); TRACE(_T("%s %s \n"), buf3,buf4); //(3) int a, b, c; swscanf_s(_T("2018-12-29"), _T("%d-%d-%d"), &a, &b, &c); TRACE(_T("%d-%d-%d"), a, b, c); //(4) TCHAR buf1[12] = { 0 }; TCHAR buf2[12] = { 0 }; swscanf_s(_T("anAB"), _T("%[a-z]%[A-Z]"), buf1, 12,buf2,12); TRACE(_T("%s ,%s"), buf1,buf2); //(5) int ip[4] = { 0 }; int ret = sscanf_s(" 192. 168.1. 213", "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]); if(ret != 4)TRACE(_T("ip error")); if (ip[0] > 255 || ip[0] <= 0 || ip[1]>255 || ip[1] <= 0 || ip[2]>255 || ip[2] <= 0 || ip[3]>255 || ip[3] <= 0) { TRACE(_T("ip error")); } else { TRACE(_T("ip ok")); }邮件地址判断,如下:
TCHAR buf1[12] = { 0 }; TCHAR buf2[12] = { 0 }; TCHAR buf3[12] = { 0 }; int ret = swscanf_s(_T("abc2018@QQ.com"), _T("%[a-zA-B0-9] %*[@] %[a-zA-Z]%*[.]%s"), buf1, 12,buf2,12,buf3,12); TRACE(_T("ret=%d: %s %s %s\n"),ret, buf1,buf2,buf3); if (ret == 3) TRACE(_T("正确的邮件地址")); else TRACE(_T("不正确的邮件地址"));
标签:swscanf_s使用
原文地址:http://blog.51cto.com/9233403/2096033