Eyla
2009-04-11 22:43:00 UTC
I’m trying to extract a substring from a text.
I text my code with a small text and it works with this cod:
String text = null;
String result = null;
text = "%This program implements the backpropagation (BPN) algprithm. It has a general structure, allowing the user to easily modify the" +
"for specific applications by changing parameters without having to recode the main body of the program.";
string start = "backpropagation (BPN)";
string end = "parameters without";
int startIndex = text.IndexOf(start);
int endIndex = text.IndexOf(end);
result = text.Substring(startIndex , endIndex);
MessageBox.Show(result);
Then I tried to download a url sorce code and store it in a string then extract asubstring from that string using this code:
string geturl = null;
string result = null;
String url = "http://www.merriam-webster.com/dictionary/good";
WebClient client = new WebClient();
geturl = client.DownloadString(url);
string start = "";
string end = "
int startIndex = geturl.IndexOf(start);
int endIndex = geturl.IndexOf(end);
result = geturl.Substring(startIndex , endIndex);
MessageBox.Show(result);
But I’m getting an error message while the runing time At this line:
result = geturl.Substring(startIndex , endIndex);
error message:
Message="Index and length must refer to a location within the string.\r\nParameter name: length"
I even tried to save the string to a text file then try to extartct but I’m getting same error too.
Please I need help to solve this problem.
Thank you,