|
-
Jan 19th, 2017, 07:36 AM
#1
Thread Starter
Lively Member
For Loop search problem
I am trying to avoid a for loop, I already have that code you have written, but I want to avoid this:
i ++
I want to check each dictionary procedurarly. It is jumping from Dictionary to Dictionary looking for matches. So, I want it to have conditions that no Dictionary can be searched until all possible matches in Dictionary 1 are found before moving to Dictionary 2.
But the problem with this code is that, if it encounters a word replaced in Dictionary 1 .E.g. I have replaced Bulk|Apple from Dictionary 1. If apple is what I have chosen. And now Apple is being replaced by another word in Dictionary 2. E.g. Apple|Passion. The code will not allow Dictionary 1 to finish scanning the whole document. Instead, it will jump to Dictionary 2 to solve that problem then jump to wherever it is it will jump next. This is a very bad code to implement. Can you help?
Code:
for (int i = 0; i < 8; i++)
{
string fileName = "dictionary.txt";
fileName = string.Format("dictionary{0}.txt", i);
using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/" + fileName)))
{
while (!reader.EndOfStream)
{
string[] parts = reader.ReadLine().Split('|');
if (richText.Contains(parts[0]))
{
if (replacements.ContainsKey(parts[0]))
{
replacements[parts[0]].Add(parts[1]);
}
else
{
List<string> newWordList = new List<string>();
newWordList.Add(parts[1]);
replacements.Add(parts[0], newWordList);
}
}
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|