请高手分析一段C#代码!急!急!
来源:百度知道 编辑:UC知道 时间:2024/05/21 00:47:07
如下:
//得到外网ip
public IPAddress GetMyIP()
{
//下载数据
WebClient client = new WebClient();
byte[] bytRecv = client.DownloadData("http://www.ip138.com/");
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);//这一句的意思请分析!谢谢!
//提取信息
string regexStr = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";//这一句请详细分析!谢谢!
string myip = Regex.Match(str, regexStr).ToString();// 这一句在C#中调试总说Regex不存在等错误,请分析!
return IPAddress.Parse(myip);
}谢谢!
//得到外网ip
public IPAddress GetMyIP()
{
//下载数据
WebClient client = new WebClient();
byte[] bytRecv = client.DownloadData("http://www.ip138.com/");
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);//这一句的意思请分析!谢谢!
//提取信息
string regexStr = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";//这一句请详细分析!谢谢!
string myip = Regex.Match(str, regexStr).ToString();// 这一句在C#中调试总说Regex不存在等错误,请分析!
return IPAddress.Parse(myip);
}谢谢!
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);//这一句的意思请分析!谢谢!
编码转化,就是说,把直接数组bytRecv的值转化成gb2312
string regexStr = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";//这一句请详细分析!谢谢!
定义一个正则表达式样式
regexp规则类包含在System.Text.RegularExpressions.dll文件中,在对应用软件进行编译时你必须引用这个文件
例如:csc r:System.Text.RegularExpressions.dll foo.cs
命令将创建foo.exe文件,它就引用了System.Text.RegularExpressions文件。