Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
I read a txt with 2 way StreamReader and File.ReadAllText after add the list

C#
foreach (string line in File.ReadAllText(@openFileDialog1.FileName).Split(','))
               {
                   if (!ary.Contains(line.ToLower()) && line.Length > 2)
                   {
                       ary.Add(line.ToLower());
                   }
               }


but contains dont work add same strings
because the strings are similar but diffrent has code how can I fix it.
So how can I check contains with hashcode
I try list,dicitonary but dont change anything
C#
TextReader txt = File.OpenText(openFileDialog1.FileName);

is work but I dont split it with easily ,because my txt file a english book :)
Posted
Updated 27-May-13 9:53am
v2
Comments
Member 9522119 27-May-13 16:15pm    
http://rapidshare.com/files/971436739/Yeni%20Metin%20Belgesi.txt it is my .txt file such as commands strings are diffrent hascode so both of them in list
Member 9522119 27-May-13 16:37pm    
and sory textreader dont work such with others

Both the code in the question and "solution" are wrong, even if you think it "works". If something works but you don't understand how, it does not work.

First of all, never use the class ArrayList it was rendered obsolete as early as of .NET Framework v.2.0, when generics were introduced. It wasn't formally parked [Obsolete] just because there is nothing wrong in using it through some legacy code. For new development, you need to use the class System.Collections.Generics.List<>. It won't require potentially unsafe element type casting.

Now, what you really need to obtain correctly split lines is the class System.IO.File.ReadAllLines: http://msdn.microsoft.com/en-us/library/system.io.file.aspx[^].

Not only your code is redundant, it's also non-portable. Please see: http://en.wikipedia.org/wiki/End-of-line[^].

—SA
 
Share this answer
 
Solved with "carriage return" split('\r') why? I dont know but its work ;)
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 4-Feb-14 14:39pm    
This is called "cheating". How can you post such thing as the answer? And, worse, how could you "accept" it as the solution?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900