基本信息
源码名称:MAC地址格式判断的有意思的方法
源码大小:1.10KB
文件格式:.cpp
开发语言:C/C++
更新时间:2021-07-18
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍

一个判断MAC地址格式的比较有意思的方法。很久之前面试时碰到的。


#include <string>
using namespace std;

bool IsMacFormat(string str)
{
	if (str.length() != 17)
	{
		return false;
	}

	string temp = str;

	for (string::iterator it = temp.begin(); it != temp.end(); it  )
	{
		switch (*it)
		{
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
			*it = '0';
			break;
		default:
			break;
		}
	}

	if (temp != "00-00-00-00-00-00")
	{
		return false;
	}

	return true;
}