我有这个代码:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
int start = content.IndexOf("profile/");
int end = content.IndexOf("'");
string result = content.Substring(start, end - start - 1);
reader.Close();
response.Close();
}
例如,我有一条长线:
<span class="message-profile-name" ><a href='/profile/daniel'>daniel</a></span>: <span class="message-text">hello everyone<wbr/> <img class='emoticon emoticon-tongue' src='/t.gif'/></span>
我想建立一个新的字符串: daniel 大家好
我该怎么做 ?在我的代码中它不起作用我得到错误异常说
ArgumentOutOfRangeException 长度不能小于零。参数名称:长度
上线:string result = content.Substring(start, end - start - 1);
在这种情况下:start = 19572 end = 2110