473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I tried the indexof and substring and now im getting error again:

If im using this code just on a text file i created that containing one long string like "dann123ylip123sharon123daniel" so its working im ggeting first time result : "dann" then "dannylip" then "dannylipsharon"

But now in the code here im using an xml file wich is very big and im using three indexof to get the specific text i want from the the file. Not like im using in the test.txt file.

And when im running the program im getting error on line:

Substring1 = ff.Substring(prevIndex, index - prevIndex);
Telling me that Length cannot be less than zero.
Parameter name: length
And when im putting the mouse on it i see that : index = 368 and prevIndex = 1194945

So what wrong with this code ( formula ) ? I thought it will work on any text file or this xml file.
Cuz when im looking on G the string G in this code its containing the text i wanted from the xml file.

This is the code:

Expand|Select|Wrap|Line Numbers
  1. private void assetid_search()
  2.         {
  3.             string Substring1;
  4.             string Substring2;
  5.             var index = 0;
  6.             var prevIndex = 0;
  7.             var test = string.Empty;
  8.             w=new StreamWriter(@"d:\german.txt");
  9.             while (true)
  10.             {
  11.                 index = tt.IndexOf("Text value", index + 1);
  12.                 if (index == -1)
  13.                 {
  14.                     break;
  15.                 }
  16.                 int t = tt.IndexOf("\"", index);
  17.                 int y = tt.IndexOf(">",t);
  18.                 g = tt.Substring(t,y-t);
  19.                 listBox2.Items.Add(g);
  20.                 Substring1 = ff.Substring(prevIndex, index - prevIndex);
  21.                 string remainingString = ff.Substring(index + g.Length);
  22.                 int remainingStringLenght = remainingString.Contains(g) ? remainingString.IndexOf(g) : remainingString.Length;
  23.                 Substring2 = ff.Substring(index + g.Length, remainingStringLenght);
  24.                 test += Substring1 + Substring2;
  25.                 prevIndex = index + g.Length + remainingStringLenght;
  26.                 w.WriteLine(test);
  27.             }
  28.             w.Close();
  29.         }
  30.  

Thanks.
Mar 22 '11 #1
0 1100

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
1
by: dereski | last post by:
Hey all, I am trying to connect to my database but I am getting error "80004005 Could Not Find File" Any Ideas as to why? I tried recreating the database again, just in case it was corrupted...
5
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
1
by: kigoobe | last post by:
Hi friends, I'm having three queries that works perfectly ... SELECT ib.id as id, ib.titre as title, ib.date_expire as date_fin, ib.created_at as date_creation, eb.content as content, '' FROM...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
12
by: tvnaidu | last post by:
Trying to mount windows folder on Linux machine, getting this error. I have a folder called "CheckIn" on windows, I made that folder as Network sharing. ON lInux, I tried to access that folder by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.