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??

7 Years
Discussion Span
Last Post by Geekitygeek
Featured Replies

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]);

Edited by Geekitygeek: n/a


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..

Edited by Nick Evan: Fixed formatting


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");

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.