【发布时间】:2017-07-30 14:03:34
【问题描述】:
我正在尝试拆分格式为“HOST:PORT”的代理,然后继续在请求中使用该端口。因此我需要一个字符串和一个int。我试过这个:
string text = ProxyList.ToString();
string[] array = text.Split(':');
string host = array[0].ToString();
int portParse = Int32.Parse(array[1]);
this.Checker(host, portParse);
string text2 = ProxyList[i];
this.Checker(host, portParse);
我不断收到此错误:System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
在这一行:`int portParse = Int32.Parse(array[1]);
感谢布鲁诺 LM
【问题讨论】:
-
ProxyList变量的类型和内容是什么? -
在调试器中运行代码。看看值是多少。我猜
text不包含您认为它包含的内容。 -
代理列表又名文本包含 4 个代理
-
67.207.95.138:8080 98.172.91.132:8080 67.207.95.138:8080 98.172.91.131:8080 1 个重复和 1 个假代理。
-
text的内容是什么?使用调试器查看或将其输出到控制台。变量中真的有 : 吗?
标签: c#