i have a text file that contains words.. how would i get each line and pass it to a variable.
here how it goes:
string variable where each line will be passed and for each line will be passed to a function
Printable View
i have a text file that contains words.. how would i get each line and pass it to a variable.
here how it goes:
string variable where each line will be passed and for each line will be passed to a function
thanks for the quick reply..
how about writing it in the textfile like this:
string1
string2
string3
you can put your text in list
see:
Code:Dim MyList As New List(Of String)
Using SR As New IO.StreamReader(you text file)
Dim strTemp() As String = Split(SR.ReadToEnd, vbCrLf)
MyList = strTemp.ToList
End Using
I could be wrong, but isn't Environment.Newline prefered over vbCrLf?
when you say you have a textfile that contains words, can we have a bit more detail on what you mean, ideally a sample of the file data, for instance is it like a dictionary with one word on one line? is it in xml? does it have several words on one line separated by commas?
not much point for xml for this kind of list but i'd store the items in a list as per the example given by Mohammed Assad.
you will need to save the new edited list when you are done. How many words are in the list btw? might by better to save these like a property bag?
I'm making an auto complete feature of my text editor and I'm looking to store all the variables, function and classes of the source code that will be edited. Most likely the text file will be used during the run time.
VS2008 code will read your text into a list.
Code:Dim lines As List(Of String) = _
(From line In IO.File.ReadAllLines("YourFileName.txt")).ToList