reading values individually from a file.

pothuri

Active member
Joined
Nov 5, 2003
Messages
28
Location
Oklahoma
hii...

I have a file containg 3 columns 100 rows of double values seperated by tabs. I am trying to read these values using the stream reader and method readline().i thought of reading each values after splitting the string using tab as the delimiter But this is returning me a string after removing the tabs. hence couldnt seperate those values.

can someone help me out with this. i am doing it in asp.net using vb. my ultimate aim is to read values from the file and store them in an array.

thanx
 
Its returning a string because it is a string. Cant you do:
Convert.ToDouble(substring(0)) to convert the string to a double?
You can also try
Double.Parse and Double.TryParse (both shared from the Double type). :)
 
thanks for the reply. i tried to implement what you said but i am getting error saying input string is incorrect
the following is what i have done.
Dim sr As StreamReader = New StreamReader(Server.MapPath("output\ds1.txt"))
Dim line As String
Dim gtemp As Double

line=sr.readline()
gtemp = Double.Parse(line)...error is generated for this line.


i will restate my problem.

i have data like this in my file seperated by tabs

93.3859137565705 56.1665989130272 81.0551783224725
93.3859137565705 56.1665989130272 81.0551783224725
etc

now i have to extract each of those numbers by reading from the file and store into an array variable....how should i be proceeding with this.


thanx






Iceplug said:
Its returning a string because it is a string. Cant you do:
Convert.ToDouble(substring(0)) to convert the string to a double?
You can also try
Double.Parse and Double.TryParse (both shared from the Double type). :)
 
Thought you were "reading each values after splitting the string using tab as the delimiter"? Thats not reflected in your code snippet. You can do something like:

Code:
        Dim arrNums As String() = line.Split(ControlChars.Tab)
        Dim k As Integer, theNumber As Double
        For k = 0 To arrNums.Length - 1
            theNumber = Double.Parse(arrNums{k))
        Next
 
thanks for the help...its working now.

JABE said:
Thought you were "reading each values after splitting the string using tab as the delimiter"? Thats not reflected in your code snippet. You can do something like:

Code:
        Dim arrNums As String() = line.Split(ControlChars.Tab)
        Dim k As Integer, theNumber As Double
        For k = 0 To arrNums.Length - 1
            theNumber = Double.Parse(arrNums{k))
        Next
 
Back
Top