Question For Loop preventing Dictionary search from Jumping file to file

Joined
Oct 13, 2016
Messages
9
Programming Experience
1-3
I want to check each dictionary procedurarly.

When I use this:
C#:
for (int i = 0; i <= 7; i++);

It is jumping from Dictionary to Dictionary looking for matches without allowing one Dictionary to complete its search first. I want it to prevent it from jumping from dictionary to Dictionary searching for matches. E.g. Dictionary 1 can be searched until all possible matches are found in the document. Then now, move to the Next Dictionary, which is Dictionary 2. Can this code perform that function by using this:
C#:
for (int i = 0; i <= 7; i+1);
instead of the first one? If not, what should I do to improve this?


C#:
        private string GetDictionaryData(string richText)
        {
            //richText = "You should accept change, and stop bad behavior. You must not do this things again.I tell the teacher.";
            StringBuilder xml = new StringBuilder();
            Dictionary<string, List<string>> replacements = new Dictionary<string, List<string>>();

            for (int i = 0; i <= 7; i+1);
            {
                string fileName = "dictionary.txt";
                if (i => 0)
                    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);
                            }
                        }
                    }
                }
            }
 
Firstly, you're suggested loop is not the solution to anything. The loop you had, i.e.
for (int i = 0; i <= 7; i++)

You should do some reading on how 'for' loops are constructed to see why your suggestion couldn't possibly work.

As for your issue, it is almost certainly caused by the fact that you have a semicolon after your 'for' loop specification, i.e.
C#:
for (int i = 0; i <= 7; i++)[B][COLOR="#FF0000"];[/COLOR][/B]
The semicolon means that that is the end of that statement, so you have, in effect, an empty loop. To be honest though, I don't see how that code could even compile as it is, because when I tried to replicate your code I got a compilation error.

I also just noticed this:
if (i => 0)

which is presumably supposed to be this:
if (i <= 0)
 
So, now this will not jump from Dictionary to Dictionary? I will remove the code once I have your approval. It was jumping from Dictionary 1 if it has AAA|BBB in Dictionary 1, to Dictionary 2 to replace BBB with CCC instead of allowing Dictionary 1 to complete its searches.

C#:
        private string GetDictionaryData(string richText)
        {
            //richText = "You should accept change, and stop bad behavior. You must not do this things again.I tell the teacher.";
            StringBuilder xml = new StringBuilder();
            Dictionary<string, List<string>> replacements = new Dictionary<string, List<string>>();

            for (int i = 0; i <= 7; i+1)
            {
                string fileName = "dictionary.txt";
                if (i <= 0)
                    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);
                            }
                        }
                    }
                }
            }
 
ok, I have seen that i+1 cannot work, but how about i=+1 at the end of the statement? How can that be implemented so that it will go through the whole file first before proceeding to the next file? And only after it has done that, it will add i=+1, which will allow it to search in the next file.. I want it to only increment the search after the current file has been searched completely for all possible matches.
 
Back
Top Bottom