Getting string info from txt file, possible?

cw2395

New member
Joined
May 23, 2016
Messages
4
Programming Experience
1-3
Howdy,

I am doing a project for data mining, below I have modified some code to create item frequency and support data calculations, but I wanted to see if I could draw in all the original string information for the RawTransactions from a txt file.

Say I had all of this in a file on desktop in a new folder and a .txt file in the folder named "info", would there be a way to draw all of it from that file?

Thanks for any help!
namespace SeniorProject
{
    class SeniorProject
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("\nSenior Project\n");

                string[] rawItems = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PistolAmmo", "GunCleaningKit  ", "PracticeTargets ",
          "FishingRod", "FishingReel ", "FishingLine ", "Hooks ", "Worms  ", "LIfeJacket", "CamoJackets", "CamoPants", "HikingBoots", "Tent", "SleepingBags", "CampStove", "Chips", "Soda" };

                int N = rawItems.Length; // total number of items

                string[][] rawTransactions = new string[20][];
                rawTransactions[0] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets " };   // 0 1 2 5
                rawTransactions[1] = new string[] { "RifleAmmo ", "GunCleaningKit  ", "PracticeTargets " };             // 1 4 5
                rawTransactions[2] = new string[] { "Rifle", "RifleAmmo ", "PistolAmmo", "GunCleaningKit  " };             // 0 1 3 4 
                rawTransactions[3] = new string[] { "Pistol", "PistolAmmo", "PracticeTargets ", "FishingRod" };   // 2 3 5 6
                rawTransactions[4] = new string[] { "PistolAmmo", "GunCleaningKit  " };                       // 3 4
                rawTransactions[5] = new string[] { "PistolAmmo", "GunCleaningKit  ", "Hooks " };             // 3 4 9
                rawTransactions[6] = new string[] { "Rifle", "RifleAmmo ", "PistolAmmo", "FishingLine " };   // 0 1 3 8
                rawTransactions[7] = new string[] { "RifleAmmo ", "FishingRod", "FishingReel " };                     // 1 6 7
                rawTransactions[8] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets ", "Worms  " }; // 0 1 2 5 10
                rawTransactions[9] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets " };           // 0 1 2 5
                rawTransactions[10] = new string[] { "Pistol", "PistolAmmo", "PracticeTargets ", "FishingRod" };   // 2 3 5 6
                rawTransactions[11] = new string[] { "RifleAmmo ", "FishingRod", "FishingReel " };                     // 1 6 7
                rawTransactions[12] = new string[] { "RifleAmmo ", "GunCleaningKit  ", "PracticeTargets " };             // 1 4 5
                rawTransactions[13] = new string[] { "PistolAmmo", "GunCleaningKit  ", "Hooks " };             // 3 4 9
                rawTransactions[14] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets " };           // 0 1 2 5
                rawTransactions[15] = new string[] { "Rifle", "RifleAmmo ", "PistolAmmo", "GunCleaningKit  " };             // 0 1 3 4 
                rawTransactions[16] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets ", "Worms  " }; // 0 1 2 5 10
                rawTransactions[17] = new string[] { "Rifle", "RifleAmmo ", "PistolAmmo", "FishingLine " };   // 0 1 3 8
                rawTransactions[18] = new string[] { "Rifle", "RifleAmmo ", "Pistol", "PracticeTargets " };   // 0 1 2 5
                rawTransactions[19] = new string[] { "PistolAmmo", "GunCleaningKit  " };                       // 3 4

                Console.WriteLine("Item List:");
                Console.WriteLine("-----------------------------------------------");
                for (int i = 0; i < rawTransactions.Length; ++i)
                {
                    Console.Write("[" + i + "] : ");
                    for (int j = 0; j < rawTransactions[i].Length; ++j)
                        Console.Write(rawTransactions[i][j] + "   ");
                    Console.WriteLine("");
                }

                List<int[]> transactions = new List<int[]>();
                transactions.Add(new int[] { 0, 1, 2, 5 });
                transactions.Add(new int[] { 1, 4, 5 });
                transactions.Add(new int[] { 0, 1, 3, 4 });
                transactions.Add(new int[] { 2, 3, 5, 6 });
                transactions.Add(new int[] { 3, 4 });
                transactions.Add(new int[] { 3, 4, 9 });
                transactions.Add(new int[] { 0, 1, 3, 8 });
                transactions.Add(new int[] { 1, 6, 7 });
                transactions.Add(new int[] { 0, 1, 2, 5, 10 });
                transactions.Add(new int[] { 0, 1, 2, 5 });
                transactions.Add(new int[] { 2, 3, 5, 6 });
                transactions.Add(new int[] { 1, 6, 7 });
                transactions.Add(new int[] { 1, 4, 5 });
                transactions.Add(new int[] { 3, 4, 9 });
                transactions.Add(new int[] { 0, 1, 2, 5 });
                transactions.Add(new int[] { 0, 1, 3, 4 });
                transactions.Add(new int[] { 0, 1, 2, 5, 10 });
                transactions.Add(new int[] { 0, 1, 3, 8 });
                transactions.Add(new int[] { 0, 1, 2, 5 });
                transactions.Add(new int[] { 3, 4 });



                
}
 
Last edited:
If you feel that you need to post that much code then you clearly haven't given the problem enough thought. I can't speak for others but, personally, I'm not even going to bother reading unless you narrow it down to just the relevant code.
 
Is that better?
My apologies, I was unaware if it would be necessary to see it as a whole or not, this is really my first go around asking for help on a forum, usually I ask in person but classes do not start back until the 6th.

Thank you for the information, I will edit further as requested as well.
 
Would that be called parsing information or storing values into an array?
Mind giving me a few more key words for the subject so I can google and give it a shot myself?

I by no means want the direct code or solution, but I would like to be pointed where to look if you dont mind :)

And thank you for the quick replies by the way.
 
I am new to coding, so I ask this question out of interest, not rudness,

Is this line bad code:

int N = rawItems.Length; // total number of items

why not just use

int totalNumberOfItems = rawItems.Length;

and leave out the comment.

Use meaningful names, and only comment where it is needed
 
Back
Top Bottom