[help] c# big dictionary menu

User Tag List

Results 1 to 6 of 6
  1. #1
    evil2's Avatar Active Member
    Reputation
    27
    Join Date
    Feb 2009
    Posts
    172
    Thanks G/R
    31/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [help] c# big dictionary

    i have this big text file of 20000+ lines of "id = name & rank" (WOW spell ids from wowhead).
    it is way too big to use inside the c# editor.

    has anyone a hint how to INCLUDE my dictionary data into the source BEFORE runtime,
    something simple like this?

    Dictionary<uint,string> Spells = new Dictionary<uint,string>()
    { <INCLUDE "resources/FILE"> };


    i currently use "single line add" at runtime:

    StreamReader f = new StreamReader("FILE");
    string line = f.ReadLine();
    while (line != null) {
    Spells.Add(Convert.ToUInt32(line.Substring(0,5)), line.Substring(6));
    line = f.ReadLine();
    }
    Last edited by evil2; 08-21-2009 at 04:56 AM.

    [help] c# big dictionary
  2. #2
    namelessgnome's Avatar Contributor
    Reputation
    108
    Join Date
    May 2007
    Posts
    263
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way you are suggesting is far from good. Never put big amounts of data in source files

    StreamReader f = new StreamReader("FILE");
    string line = f.ReadLine();
    while (line != null) {
    Spells.Add(Convert.ToUInt32(line.Substring(0,5)), line.Substring(6));
    line = f.ReadLine();
    }

    is bugged. since it only works with fixed length lines.

  3. #3
    evil2's Avatar Active Member
    Reputation
    27
    Join Date
    Feb 2009
    Posts
    172
    Thanks G/R
    31/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not "suggesting".. i WANT it this way

    so c# has no kind of <include> function?

  4. #4
    namelessgnome's Avatar Contributor
    Reputation
    108
    Join Date
    May 2007
    Posts
    263
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason for not having include in C# is to avoid people doing this kind of thing.

    even languages that are less stricter than C# does not support that kind of thing.

    You could use a pre-build script and some custom executable to insert the data into the code file, but that would keep the data in the C# file.

    You could use nAnt and code some custom modules to make this work, but why do you even o this?

  5. #5
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
            void LoadFile(string filePath)
            {
                using (TextReader tr = new StreamReader(filePath))
                {
                    string contents = tr.ReadToEnd();
                    string[] lines = contents.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    foreach (string line in lines)
                    {
                        string[] split = line.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (split.Length != 2)
                            continue;
    
                        Spells.Add(Convert.ToUInt32(split[0]), split[1]);
                    }
                }
            }
    You could even do the above, using a text file or stream located in the application resources. (When you add a .txt file to the resources, accessing it from Properties.Resources.MyTextFile returns a string (the contents of the file))
    Last edited by Apoc; 08-22-2009 at 09:54 PM.

  6. #6
    evil2's Avatar Active Member
    Reputation
    27
    Join Date
    Feb 2009
    Posts
    172
    Thanks G/R
    31/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, i googled alot yesterday, apart from namelessgnome words of advice

    and there is really no other (easy) way than streamreading from embedded resources,
    if i want to keep everything in my program file.

    thanks apoc for the code snipper, but my wowheadcom-parser script already takes care of the format job
    Last edited by evil2; 08-23-2009 at 03:28 AM.

Similar Threads

  1. [Selling] Need help selling big accounts
    By xjsnowx in forum WoW-US Account Buy Sell Trade
    Replies: 0
    Last Post: 04-25-2014, 08:50 PM
  2. Looking For a php/html help on big project.
    By ZLau in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 01-05-2011, 10:55 AM
  3. Need Some Big Help~~~~~~
    By endlessbounty in forum World of Warcraft Emulator Servers
    Replies: 9
    Last Post: 11-27-2007, 11:57 PM
  4. Big ass problem and needing help.
    By kalish in forum WoW ME Questions and Requests
    Replies: 3
    Last Post: 12-14-2006, 08:32 PM
All times are GMT -5. The time now is 02:37 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search