|
-
Dec 12th, 2009, 06:40 AM
#1
Thread Starter
Lively Member
textfile to variable
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
-
Dec 12th, 2009, 07:38 AM
#2
Addicted Member
Re: textfile to variable
 Originally Posted by xpinvader
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
You could use a Stream Reader...
Code:
Dim sr As StreamReader = File.OpenText(your file name here)
Dim ReadBuffer As String = String.Empty
While sr.Peek <> -1
ReadBuffer = sr.ReadLine
' Pass the ReadBuffer to your Function.
End While
-
Dec 12th, 2009, 09:30 AM
#3
Thread Starter
Lively Member
Re: textfile to variable
thanks for the quick reply..
how about writing it in the textfile like this:
string1
string2
string3
-
Dec 13th, 2009, 12:08 AM
#4
New Member
Re: textfile to variable
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
-
Dec 13th, 2009, 07:53 AM
#5
Re: textfile to variable
I could be wrong, but isn't Environment.Newline prefered over vbCrLf?
-
Dec 13th, 2009, 08:42 AM
#6
Fanatic Member
Re: textfile to variable
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?
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 13th, 2009, 08:56 AM
#7
Thread Starter
Lively Member
Re: textfile to variable
 Originally Posted by Megalith
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?
just one word per line.. i will use it to store all variable names that will be placed in the richtextbox. I have a problem when the user deletes the variable, it is still in the textfile. but which is better the textfile or an xml?
-
Dec 13th, 2009, 09:09 AM
#8
Fanatic Member
Re: textfile to variable
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?
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-
Dec 13th, 2009, 09:59 AM
#9
Thread Starter
Lively Member
Re: textfile to variable
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.
-
Dec 14th, 2009, 09:12 AM
#10
Re: textfile to variable
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|