7 Replies - 919 Views - Last Post: 31 August 2013 - 02:37 AM Rate Topic: -----

#1 Mucca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 13

Reading multiple lines in .txt files task

Posted 29 August 2013 - 02:10 AM

I'm trying to make my program read all lines in the text file which contains many user/pass. what do I use instead of
Dim exmaple As String() = IO.File.ReadAllText("exmaple.txt").Split(":")

Is This A Good Question/Topic? 0
  • +

Replies To: Reading multiple lines in .txt files task

#2 ybadragon  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 277
  • View blog
  • Posts: 1,469
  • Joined: 11-May 12

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 05:15 AM

Why do you want to use something other than that? Is the file in a certain format? We need more information.
Was This Post Helpful? 0
  • +
  • -

#3 Mucca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 13

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 05:18 AM

the text file contains multiple lines for multiple accounts. and IO.File.ReadAllText only reads 1 string (the first line)
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 05:22 AM

View PostMucca, on 29 August 2013 - 03:10 AM, said:

I'm trying to make my program read all lines in the text file which contains many user/pass. what do I use instead of
Dim exmaple As String() = IO.File.ReadAllText("exmaple.txt").Split(":")

When you say "lines", I would assume you want to split the text into lines first. If the ":" is the delimiter between username and password, you would then want to split the lines with the ":".
So your first Split delimiter should be something like vbNewLIne, then you can ise something like:

        credentials = example(n).Split(":")

This assumes that n is a variable, perhaps in a loop, or perhaps in a name/password lookup.
Was This Post Helpful? 0
  • +
  • -

#5 ybadragon  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 277
  • View blog
  • Posts: 1,469
  • Joined: 11-May 12

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 05:22 AM

ReadAllText reads all of the file and puts it into 1 String, it doesn't read the first line only. It may have an issue with the .Split(":") though. In the file, is each line seperated by a colon, or are they just on new lines, or is each uname/pword pair seperated by a colon like so (testUser:testPassword)?

This post has been edited by ybadragon: 29 August 2013 - 05:22 AM

Was This Post Helpful? 0
  • +
  • -

#6 Mucca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-May 13

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 12:39 PM

View Postybadragon, on 29 August 2013 - 05:22 AM, said:

ReadAllText reads all of the file and puts it into 1 String, it doesn't read the first line only. It may have an issue with the .Split(":") though. In the file, is each line seperated by a colon, or are they just on new lines, or is each uname/pword pair seperated by a colon like so (testUser:testPassword)?

it looks like this

user1:user1
user2:user2
Was This Post Helpful? 0
  • +
  • -

#7 ybadragon  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 277
  • View blog
  • Posts: 1,469
  • Joined: 11-May 12

Re: Reading multiple lines in .txt files task

Posted 29 August 2013 - 12:54 PM

I would Try .Split(vbNewLine)

That will return all of the lines, then you can loop through the items in the array to get the individual usernames and passwords.
Was This Post Helpful? 0
  • +
  • -

#8 Scarab48  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 15-August 13

Re: Reading multiple lines in .txt files task

Posted 31 August 2013 - 02:37 AM

Try something like this, loops trough all the lines in the file.
Dim exmaple As String() = IO.File.ReadAllText("exmaple.txt")
Dim lines() As String = Split(exmaple, vbCrLf)
For Each line As String In lines
           'code for where you want to put each line
Next

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1