C#: reading in a text file more 'intelligently'
Posted
by
DarthSheldon
on Stack Overflow
See other posts from Stack Overflow
or by DarthSheldon
Published on 2014-05-27T21:34:41Z
Indexed on
2014/05/28
21:27 UTC
Read the original article
Hit count: 111
I have a text file which contains a list of alphabetically organized variables with their variable numbers next to them formatted something like follows:
aabcdef 208
abcdefghijk 1191
bcdefga 7
cdefgab 12
defgab 100
efgabcd 999
fgabc 86
gabcdef 9
h 11
ijk 80
...
...
I would like to read each text as a string and keep it's designated id# something like read "aabcdef" and store it into an array at spot 208.
The 2 issues I'm running into are:
I've never read from file in C#, is there a way to read, say from start of line to whitespace as a string? and then the next string as an int until the end of line?
given the nature and size of these files I do not know the highest ID value of each file (not all numbers are used so some files could house a number like 3000, but only actually list 200 variables) So how could I make a flexible way to store these variables when I don't know how big the array/list/stack/etc.. would need to be.
© Stack Overflow or respective owner