起始索引不能小于零和“问题 [英] Start index cannot be less than zero and " problem

查看:112
本文介绍了起始索引不能小于零和“问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用它时,它在第8行说startindex不能小于零,我需要写< pre class =df-rawid =registryData>但是当我试着把它放进课堂而其他2个单词留在之外请帮助我



我尝试了什么:



hi when i try to use it it says "startindex cannot be less then zero" in 8th line and i need to write <pre class="df-raw" id="registryData"> but when i try to put it into "" class and other 2 words stays outside of the "" pls help me

What I have tried:

string website =("https://www.whois.com/whois/" + domainname.ToString());
            WebRequest request = HttpWebRequest.Create(website);
            WebResponse answer;
            answer = request.GetResponse();
            StreamReader info = new StreamReader(answer.GetResponseStream());
            string cinfo = info.ReadToEnd();
            int start = cinfo.IndexOf("<pre class="df-raw" id="registryData">");
            int finish = cinfo.Substring(start).IndexOf("</pre>");
           string scinfo = cinfo.Substring(start,finish);
            rtxtregistery.Text = scinfo;

推荐答案

文档 [ ^ ]声明:

The documentation[^] states:
Quote:

如果找到该字符串,则从零开始的索引位置值,如果不是,则返回-1。如果value为String.Empty,则返回值为0.

The zero-based index position of value if that string is found, or -1 if it is not. If value is String.Empty, the return value is 0.




int start = cinfo.IndexOf("<pre class="df-raw" id="registryData">");
int finish = cinfo.Substring(start).IndexOf("</pre>");



您假设文本存在...要修复:


You are assuming that the text exists... To fix:

int start = cinfo.IndexOf("<pre class=\"df-raw\" id=\"registryData\">");
if (start >= 0)
{
    int finish = cinfo.Substring(start).IndexOf("</pre>");
    if (finish >= 0)
    {
        rtxtregistery.Text = cinfo.Substring(start, finish);
    }
}


这篇关于起始索引不能小于零和“问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆