hi,
i have two values in each line seperated by space in notepad. what i have to do is to store the first value in one variable and the other in another variable.
so, wat should i do??

Read your previous thread as a start.

Read your previous thread as a start.

sorry i didnt got u

ddanbe is refering to his reply in your other thread:here.

Since you are posting them as seperate issues and ddanbe and diamonddrake have given you the code to read in the contents of the file i wont go over that. To split the string you can do something like:

string input = "test 3";
            string[] variables = input.Split(' ');

            string outputString = variables[0];
            int outputInteger = Convert.ToInt32(variables[1]);

hi,
i used the following code but getting problem with it

private void button1_Click(object sender, EventArgs e)
        {
            StreamReader sw = new StreamReader("c: \\key.txt");
            line = sw.ReadLine();
            Console.WriteLine(line);//its showing the output             
            string[] variables = line.Split('  '); 
              float outputString = float.Parse(variables[0]);//this line is showing error while runnig.

can u help plz..

Which error? It probably means that variables[0] is not conform to the format of a float. Did you check that?

As ddabe said, it is very hard for us to debug the code if we dont know the error. Lets us now the full message that is displayed so we can figure out what is causing it. Also, is the Console.WriteLine(line); definitely showing the right values? You have an errant whitespace in your filename...not sure if that will make a differance, but something to check :) StreamReader sw = new StreamReader("c:[U] [/U]\\key.txt");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.