您好,登錄后才能下訂單哦!
//(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)IP地址 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("不正確的郵件地址"));
取出串口號后的數字,如下:
CString strCOM = _T("COM12"); TCHAR buff[10] = {}; swscanf_s(strCOM, _T("%*[a-zA-Z]%[0-9]"), buff, 10); TRACE(_T("%s\n"),buff);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。