Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading a simple datafile and storing info

Status
Not open for further replies.

vviti

Programmer
Mar 10, 2005
9
US

I am wondering if there is an easy way to read in structured text datafiles and assign to an array element each value read
in. This is something very simple in Fortran or C, but so far it's been eluding me in .net. What I am doing now is that I read in a file and read line by line and split each line up into fixed lengths, each substring containing an element (number) that I save in an array. However, when the spacing between the numbers in the text file changes, it is truncating the numbers. This is what I am doing now:

Line = objReader.ReadLine()
Node_1(n) = Line.Substring(17, 6) - 1
Node_2(n) = Line.Substring(25, 6) - 1
Node_3(n) = Line.Substring(33, 6) - 1

This is an example of an ASCII data file that I am interested in reading (much longer than this):

929 930 927 928 925 926 923 924 921 922
919 920 917 918 915 916 913 914 911 912
909 910 907 908 905 906 889 890 891 892

Thanks!

Valerio
 
there is a MS ODBC driver for text files. It allows you to set up an ODBC connection to your text file.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
If each field is separated by a space then then it would be worth invesitgating split

dim node() as string
node = line.split(" ")




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top