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
- private void assetid_search()
- {
- string Substring1;
- string Substring2;
- var index = 0;
- var prevIndex = 0;
- var test = string.Empty;
- w=new StreamWriter(@"d:\german.txt");
- while (true)
- {
- index = tt.IndexOf("Text value", index + 1);
- if (index == -1)
- {
- break;
- }
- int t = tt.IndexOf("\"", index);
- int y = tt.IndexOf(">",t);
- g = tt.Substring(t,y-t);
- listBox2.Items.Add(g);
- Substring1 = ff.Substring(prevIndex, index - prevIndex);
- string remainingString = ff.Substring(index + g.Length);
- int remainingStringLenght = remainingString.Contains(g) ? remainingString.IndexOf(g) : remainingString.Length;
- Substring2 = ff.Substring(index + g.Length, remainingStringLenght);
- test += Substring1 + Substring2;
- prevIndex = index + g.Length + remainingStringLenght;
- w.WriteLine(test);
- }
- w.Close();
- }
Thanks.