VB equivalent of fscanf in C

S

Sam

Hi everyone

This some sort relates to a question that posted couple of day ago.
Basically I have a text file which consists of number of lines with the
following format. Each line is terminated by LF and each value is separated
by either a tab or number of spaces. The problem I have is that I have to
read each of the values into separate variables. For example, the first line
requires in 4 different variables to hold 4 values

1 0.000016 7.999882 0.000000
2 1.000013 7.999875 0.000000 0.005555

In a c console application, I use fscanf function to scan all the values of
a non-blank line till I hit a LF and ignore any control characters or empty
line. Could anyone tell me if we have some function like fscanf in .Net?
What's the best way to approach this problem. Any suggestions are greatly
appreciated.

Regards,

Sam
 
C

Cor Ligthert

Sam,

I saw Chris was busy with your problem an asked more information about that.

Is it not better to answer that question from Chris first than starting a
new message thread.

Cor
 
G

Guest

If I was in your position then I'd read each line in and then split it by
comma using stream reader

You could also us stream reader to readToEnd() & then split it by
contolChars.Lf, which is the line feed char you were talking about.
 
S

Sam

Hi Cor

My apologies to you guys and Chris. Chris actually has answered my question
which is when I need to write to a text file and I'd like to thank him for
that. Now since this question is slightly changed and I thought may be I
should post a new message.

Regards,

Sam
 
S

Sam

Hi Crouchie

For each line I first to use the Trim function to trim any blank spaces and
tabs at both ends of a line then split the data and throw out any blank
spaces. The problem is that each of my field data is separated by more than
one field separators. User could separate each field by a number of space
characters instead of 1. I feel like there must be a better or more
efficient way to do this

Regards,

Sam
 
C

Cor Ligthert

Sam,

I was waiting because mostly is Paul Clement answering on these questions
either if I give an answer or not. His answers about that became every time
better and better so I stopped to answer those questions.

I thought that a file delimited with tabs can as well be used as a CSV file.
Therefore would be that for me the first thing to look at.

Have a look at this one.
http://groups-beta.google.com/group/microsoft.public.dotnet.languages.vb/msg/4b86baee7cbd8616

When this does not help, have than a search on "Paul Clement CSV" because
he has dropped a lot of samples with variants.

I hope this helps,

Cor
 
S

Sam

Hi Cor

Thanks for the suggestions and the link I think I somewhat got what I tried
to implement. Basically I use split method to break a line into substrings
and store them in an array. I then loop through this array and throw out all
strings that are "space" or tab. The remaining numeric strings, I put them
back into variables. This method works some what but I feel like it's kinda
insufficient because I have to loop through entire array of strings
including those "space" strings

Regards,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top