我编写了一个程序来地理定位发件人的通用位置,但是我在从字符串中提取 IP 地址时遇到问题,例如:
public static string getBetween(string strSource, string strStart, string strEnd)
{
int Start, End;
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
else
{
return "";
}
// 我已经将完整的 EMAIL 的 MIME 数据捕获到一个字符串 (txtEmail) // 现在我搜索字符串 ...
//THIS IS MY PROBLEM. this is always different.
// I need to capture only the IP address between the brackets
string findIP = "X-Originating-IP: [XXX.XXX.XXX.XXX]";
string data = getBetween(findIP, "[", "]");
txtCustomIPAddress.Text = data;
有任何想法吗?