Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have an application where i have created a textfile in the resources section of my project and wanted to know if anyone can tell me how i can read that textfile and split the text in it?

i have tried the following two methods but they don't work where i am wanting to display the contents of my text file 'ResourceFile.txt' into a textbox called 'FileReader'.

VB
Dim fileReader As String
fileReader = FileSystem.ReadAllText("ResourceFile.txt")
FileReader.Text.Split(fileReader, " ")


and

VB
Imports system.IO
Dim ioFile as new StreamReader("ResourceFile.txt")
Dim ioLine as string
Dim ioLines as string
ioLine = ioFile.ReadLine
ioLines = ioLine
While not ioLine = ""
ioLine = ioFile.ReadLine
ioLines = ioLines & vbcrlf & ioLine
End While
FileReader.Text.Split = (ioLines, " ")
ioFile.close


thanks to any helpers.
Posted

1 solution

Try this:
VB
Dim fileReader As String
fileReader = FileSystem.ReadAllText("ResourceFile.txt")
FileReader.Text=fileReader


And by the way, it's very confusing and general bad practice to have a string named fileReader and a textbox named FileReader. You need to start using some kind of naming convention before you go crazy. Put some kind of code before your variable name to distinguish that it's a string or a textbox. For example, name your textbox txtFileReader and the string strFileReader.

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900