CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    11

    Is ther a way to place the keys and values in a hashtable in order?

    Hi

    I want to place the keys and values in a hashtable in order, but they seem to place as they want.

    I have the code

    FileStream fs1 = new FileStream(file, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite);
    StreamReader testTxt = new StreamReader(fs1);
    string allRead = testTxt.ReadToEnd(); //Reads the whole text file to the end
    Hashtable test = new Hashtable();
    int tal = 0;
    for (int i = 0; i < allRead.Length; i++)
    {

    if (char.GetNumericValue(allRead[i]) <= 127 && char.GetNumericValue(allRead[i])>=0)
    {
    //tal++;
    test.Add(i,allRead[i].ToString( ));
    //test.Add(tal,allRead[i].ToString( ));
    }
    }

    In the hashtable test the keys and values are not placed in order. And when I use Add with "tal" it places the keys and values before each other.
    Is there away to place them in order with "i" and "tal"?

    And a nother question I'm using this code to see if the file contains ordninary characters and I thought that if that "tal" is almost the same size as allRead.Length it would be a text file. But it doesnt work that either.

    Can anyone help me with both the question.

    Many thanks
    Fia

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Is ther a way to place the keys and values in a hashtable in order?

    There is a way - use a List<string> instead. Dictionary and Hashtable types are *not* sorted. They are optimised to have ultra-fast lookups and so store the keys in a special way which you cannot really affect. What are you trying to accomplish anyway?
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Jul 2006
    Posts
    11

    Re: Is ther a way to place the keys and values in a hashtable in order?

    Hi

    Thanks for your answer.
    I want to search for words in text files (.doc, .txt)
    I'm trying to see if a file contains valid characters (a-ö, A-Ö, 0-9) and some characters like ".", "," and so on. I thought if I counted these characters and they are almost as many and the length of allRead it would be a text file.

    I have files ( .doc) that I have scanned pictures to and if I for example search after "is" it can find that in the document with the scanned picture. When I open the document the file doesn't contain the word "is".

    Hope you undertstand what I mean and can help me

    Thanks
    Fia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured