private string IPandPort(string temp)
{
string ipandport = temp;
string[] strDetail = ipandport.Split(":".ToCharArray());
string iptemp = strDetail[0];
string porttemp = strDetail[1];
string[] ipDetail = iptemp.Split(".".ToCharArray());
string ip = "";
string port="";
for (int i = 0; i < ipDetail.Length; i++)
{
if (ipDetail[i].Length < 3)
{
if (ipDetail[i].Length == 0)
{
ipDetail[i] = "000";
}
else if (ipDetail[i].Length == 1)
{
ipDetail[i] = "00" + ipDetail[i];
}
else if (ipDetail[i].Length == 2)
{
ipDetail[i] = "0" + ipDetail[i];
}
}
}
ip = ipDetail[0] + "." + ipDetail[1] + "." + ipDetail[2] + "." + ipDetail[3];
if (porttemp.Length < 5)
{
if (porttemp.Length == 1)
{
port = "0000" + porttemp;
}
else if (porttemp.Length == 2)
{
port = "000" + porttemp;
}
else if (porttemp.Length == 3)
{
port = "00" + porttemp;
}
else if (porttemp.Length == 4)
{
port = "0" + porttemp;
}
}
else
{
port = porttemp;
}
string ipport=ip+port ;
return ipport ;
}
将IP+Port转换成标准格式***.***.***.***:*****
最新推荐文章于 2021-12-29 14:37:34 发布
本文介绍了一个用于处理IP地址和端口字符串的方法。该方法能够接收一个包含IP地址和端口的字符串,并将其格式化为统一的标准形式,确保每个部分都有固定的长度,方便在网络通信中使用。
847

被折叠的 条评论
为什么被折叠?



