Click here to Skip to main content
15,797,923 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:

C#
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;
Posted
Updated 2-Sep-17 2:23am
v2
Comments
Richard MacCutchan 2-Sep-17 7:16am    
It means that one of your values is -1 which indicates that it did not find the pattern you are searching for.

1 solution

The documentation[^] states:
Quote:
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.

C#
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:
C#
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);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900