Question Reading Text into an Array with WebClient

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Can the WebClient class be used to read a txt directly into an array? If so, how is it done?
 
No, not quite. The WebClient can be used to download directly to a file, a single String or a Byte array. If you're downloading text and you want an array then you would probably call the DownloadString method and then call the Split method of that String to break it into an array. I'm guessing that you want the text broken into lines, which would look something like this:
Dim lines = myWebClient.DownloadString(url).Split({ControlChars.CrLf, ControlChars.Lf}, StringSplitOptions.None)
That will split the text into lines whether it uses carriage returns and line feeds for line breaks, just line feeds or a combination of both.
 
Back
Top