pothuri Posted March 29, 2004 Posted March 29, 2004 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 Quote
Leaders Iceplug Posted March 29, 2004 Leaders Posted March 29, 2004 It's returning a string because it is a string. Can't 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). :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
pothuri Posted March 30, 2004 Author Posted March 30, 2004 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 It's returning a string because it is a string. Can't 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). :) Quote
JABE Posted March 30, 2004 Posted March 30, 2004 Thought you were "reading each values after splitting the string using tab as the delimiter"? That's not reflected in your code snippet. You can do something like: 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 Quote
pothuri Posted March 30, 2004 Author Posted March 30, 2004 thanks for the help...its working now. Thought you were "reading each values after splitting the string using tab as the delimiter"? That's not reflected in your code snippet. You can do something like: 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.