Avatar of Alex E.
Alex E.
 asked on

asp.net c# read lines of text file and put each row in mutliple variables variables not updated

About this code you helped me here:

List<string> contents = File.ReadAllLines(@"C:\Working Directory\test.txt").ToList();
Dictionary<string, string> vars = new Dictionary<string, string>();
foreach( string line in contents ) {
    string[] parts = line.Split(new char[] {'='}, StringSplitOptions.RemoveEmptyEntries);
    string key = parts[0].Substring(4).Trim();
    string value = parts[1].Replace("'", "").Trim();
    vars.Add ( key, value );
}

Open in new window


To read each line and gives the var the value in a string variable of similar items like:

var p1='Question 1'
var a1a='Answer1 1'
var a1b='Answer1 2'
var a1c='Answer1 3'
var a1d='Answer1 4'
var e1a='Incorrect'
var e1b='Incorrect'
var e1c='Incorrect'
var e1d='Correct'

Open in new window


I tested and after your "vars.Add(key, value);" I added for example one supposed created variable respe1.Text = e1d; and e11d does not have any value but if I check "key" and "value" both have values. Then how could you update the key and value to obtain the key the value like a variable? In other words like example make something like e1d="Correct" if entered manually.  Maybe after vars.Add requires an update or something?
ASP.NETVisual Basic.NETC#.NET Programming

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Alex E.

ASKER
Worked. Thank you
Fernando Soto

Not a problem Alex, glad to help.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck