Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

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

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...