Naming a variable from a text file

Related searches

I'm making a program in C# that uses mathematical sets of numbers. I've defined the class Conjunto (which means "set" in spanish). Conjunto has an ArrayList that contains all the numbers of the set. It also has a string called "ID" which is pretty much what it sounds; the name of an instance of Conjunto. The program have methods that applies the operations of union, intersection, etc, between the sets. Everything was fine, but now i've a text file with sentences like:

  • A={1,2,3}
  • B={2,4,5}
  • A intersection B
  • B union A

And so on. The thing is, i don't know how many sets the text file contains, and i don't know how to name the variables after those sentences. For example, name an instance of Conjunto A, and name another instance B.

Sorry for the grammar, english is not my native language.

Thanks!

It's pretty complicated to create varaibles dynamically, and pretty useless unless you have some already existing code that expects certain variables.

Use a Dictionary<string, Conjunto> to hold your instances of the class. That way you can access them by name.

Creating a text file with a variable as the name of the text file, Binary storage saves variables extracted from all files imported into the window. These variables can be inserted into text labels or worksheet cells using the Insert� Assign Variable Names from a Text File. Learn more about read varible names, read text, assign varible names

First off, If you don't target lower version than .Net 2.0 use List instead of ArrayList. If I were you I wouldn't reinvent the wheel. Use HashSet or SortedSet to store the numbers and then you can use defined union and intersection.

Secondly, what is your goal? Do want to have just the output set after all operations? Do you want to read and store all actions and them process it on some event?

Help Online - Origin Help, "Could not parse the file contents as a data set. There were too many variable names in the first line of the text file.". @Tvern - I'm providing a GUI interface for the users to maintain the variable values, so they really should not need to edit the variable text file (using Excel or SQLite). And if comments are allowed in the .ini files (as per my question above) then I could provide explanatory comments directly in the file.

First of all, your program is taken from bad side. I would advice to start making new one. One of ways to name "variables" dynamicaly is by making class objects and editing their properties.

This is what I made as a starting platform:

First af all I have crated a class called set

class set
    {
        public string ID { get; set; }
        public List<int> numbers { get; set; }
    }

Then I have made the code to sort whole textfile into list of those classes:

            List<set> Sets = new List<set>();
            string textfile = "your text file";
            char[] spliter = new char[] { ',' };  //switch that , to whatever you want but this will split whole textfile into fragments of sets
            List<string> files = textfile.Split(spliter).ToList<string>();
            int i = 1;
            foreach (string file in files)
            {
                set set = new set();
                set.ID = i.ToString();

                char[] secondspliter = new char[] { ',' };  //switch that , to whatever you want but this will split one set into lone numbers
                List<string> data = textfile.Split(secondspliter).ToList<string>();
                foreach (string number in data)
                {
                    bool success = Int32.TryParse(number, out int outcome);
                    if (success)
                    {
                        set.numbers.Add(outcome);
                    }

                }
                i++;
                Sets.Add(set);
            }

Hope it helps someone.

Solved: Photoshop Variables, Hello, I am wanting to write text file where the file name will created using an assign Activity what is the variable of inputDataTable? This command just creates a temporary text file using the temp variable and the FileDateTime variable with a .bak extention. The contents of the text file is “This is a test file” and the name of the file is:

Dynamic File name in 'Write text File' - Build, I have imported a TXT file into my sas document that does not have any variable names and is being run as one column instead of 3. Please� For what it's worth the script is supposed to get the name of each VM Host in our environment, create a list of VM Guests that are on it, then output that info to a file which includes the name of the host, e.g. C:\vm\Host1_VMs.txt, C:\vm\Host2_VMs.txt, C:\vm\Hostn_VMs.txt, etc. Thanks in advance!

Adding variable names to an imported txt file, I want to create a new file from python but I want the filename to be the value of a variable. I've used commands and touch but it won't use the value but the variablename instead.

Hi, I am new to Matlab. I have some text files named as a_201706280202.txt, a_201706280402.txt, a_201706280204.txt, a_201706280404.txt, etc. Once they are loaded in the workspace, I want to call (name) them as variables such as A1, A2, B1, B2, etc. based on some criteria.

Comments
  • Thanks a lot! I'm going to try that,
  • My goal is to execute the operations and then print them on another .txt. Anyway, i've come (thanks to your replies people) to do it. Thanks!