Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Grabbing strings from a web server and turning it into an array of strings

How would I go about grabbing an array of strings from a text file on a web server?


like:
Code
{ "testing", "testt", "test" }

Also how would the text file on the web server need to be formatted? JSON?

Is this even possible? I really would like to learn how. I just started learning VB in august.

Thank you.
You can use webrequests to read a file, and split it using "," cchar as your example above, i don't know any other way without using a split character.

Step at a Step, use this to read:
http://stackoverflow.com/questions/24712...m-internet

It's c#, follow the 2nd upvoted answer. you can use http://converter.telerik.com/ to convert to vb if you need.

Then use http://msdn.microsoft.com/en-us/library/...10%29.aspx to split.
(Nov 17, 2014 03:42 PM)CatSoup Wrote:  like:
Code
{"testing", "testt", "test"}
Code
Private WebClient As Net.WebClient
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      WebClient = New Net.WebClient
      Dim Source As String = WebClient.DownloadString("url here")
      'For Testing: 'Dim Source As String = "{" & """" & "testing" & """" & ", " & """" & "testt" & """" & ", " & """" & "test" & """" & "}"
      Source = Source.Substring(Source.IndexOf(""""))
      Dim Array As String() = Source.Split("""" & ", " & """")
      For i As Int16 = 1 To Array.Length Step 2
      Console.WriteLine(Array(i))
      Next
    End Sub

+1 for liking Blue Exorcist (not adding to your rep, just stating the fact). :)
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.
(Nov 17, 2014 04:25 PM)Eternal Darkness Wrote:  -snip

That was an example of an array, not the actual format of the page. Even at that, weird way to do it I think!

(Nov 17, 2014 03:42 PM)CatSoup Wrote:  How would I go about grabbing an array of strings from a text file on a web server?

Easy way is to download page as a string.

(Nov 17, 2014 03:42 PM)CatSoup Wrote:  Could the text file on the web server need to be formatted? JSON?

It can be any format you like or it can be plain text, you'll create the array through splitting with whatever you put as your delimiter.
(Nov 17, 2014 04:29 PM)Odus Wrote:  That was an example of an array, not the actual format of the page.

If the page only contains (such as a random plain text file on your server or w/e):
(Nov 17, 2014 03:42 PM)CatSoup Wrote:  like:
Code
{"testing", "testt", "test"}
The code I posted will delimit it properly and load it into an array that you can sort through...

He did not ask how to create a list for his web server, but how to retrieve a list in said format from his web server... If I am understanding correctly that is...

(Nov 17, 2014 04:29 PM)Odus Wrote:  Even at that, weird way to do it I think!

Well, it works...
I just threw it together a second ago...
Personally I would probably use SubStrings in a loop, gives me a bit more control and will possibly end up being a millionth of a second faster... You mentioned spiting the string with a delimiter, so I thought I would throw it together that way... "The method I suggested is weird"... xD
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.
(Nov 17, 2014 04:32 PM)Eternal Darkness Wrote:  If the page only contains (such as a random plain text file on your server or w/e):
The code I posted will delimit it properly and load it into an array that you can sort through...

He did not ask how to create a list for his web server, but how to retrieve a list in said format from his web server... If I am understanding correctly that is...

Well, it works...
I just threw it together a second ago...
Personally I would probably use SubStrings in a loop, gives me a bit more control and will possibly end up being a millionth of a second faster... You mentioned spiting the string with a delimiter, so I thought I would throw it together that way... "The method I suggested is weird"... xD

nono. I need something that will grab strings from a file formatted like this:

Code
testing
test
testt

and then use it in an array like:
Code
{ "testing", "test", "testt" }
(Nov 17, 2014 05:14 PM)CatSoup Wrote:  nono. I need something that will grab strings from a file formatted like this:

Code
testing
test
testt

and then use it in an array like:
Code
{ "testing", "test", "testt" }

TOLD YOU ETERNAL! Forgive my code, I've spent the last 2 weeks in Swift but you should be good with this:
Code
Using wc As New WebClient()
    Dim s() As String = wc.DownloadString(“url.com/file.txt”).Split(vbCrLf)
End Using
(Nov 17, 2014 05:19 PM)Odus Wrote:  TOLD YOU ETERNAL! Forgive my code, I've spent the last 2 weeks in Swift but you should be good with this:
Code
Using wc As New WebClient()
    Dim s() As String = wc.DownloadString(“url.com/file.txt”).Split(vbCrLf)
End Using

So I have this:
Code
Imports System.Net

Public Class Form1

    Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGen.Click
      Using wc As New WebClient()
      Dim grabAccounts() As String = wc.DownloadString("codercannon.com/lol.txt").Split(vbCrLf)

      End Using

    End Sub
End Class

How would I grab a random string from that url and display it into a textbox?
(Nov 17, 2014 05:45 PM)CatSoup Wrote:  So I have this:
Code
Imports System.Net

Public Class Form1

    Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGen.Click
      Using wc As New WebClient()
      Dim grabAccounts() As String = wc.DownloadString("codercannon.com/lol.txt").Split(vbCrLf)

      End Using

    End Sub
End Class

How would I grab a random string from that url and display it into a textbox?

Again, its been a while but here goes:
Code
Dim R As System.Random = New System.Random()
TextBox1.Text = S(R.Next(0, S.Length))
Disregard everyone above me

If you want to do what you are asking correctly, keep on reading

Firstly, you'll make life easier on yourself if you change your json a bit. What I mean is make it an actual array, or at least a JSON array
Code
["testing","test","tester"]

Now that you have that, the way to parse that information in VB, correctly, is using some sort of JSON deserializer
http://james.newtonking.com/json
That link takes you to the site of an awesome and powerful library that can work with JSON
The thing is, it adds an additional dependency at about 500 kb

An alternative is to use the DataContractJsonSerializer, which is included in the .NET framework since version 4.0

If you decide to use the DataContractJsonSerializer, I've written a very simple helper class to make it a more flawless experience
https://gist.github.com/PatPositron/e6df...76343824ee

Just throw that in your project, and you can continue

Congratulations, that was the hardest step
All you need to do now is get the JSON data from wherever you are supplying it, and pass it to the helper class like so:
Code
Dim myArrayOfStrings = JsonHelper.Deserialize(Of List(Of String))(myJsonString)

It will populate `myArrayOfStrings` with all the data that was in your JSON

------EDIT------
Annnnndddd I just read your reply farther up the thread:
(Nov 17, 2014 05:14 PM)CatSoup Wrote:  nono. I need something that will grab strings from a file formatted like this:

Code
testing
test
testt

and then use it in an array like:
Code
{ "testing", "test", "testt" }

Imma go ahead and leave now, but if you know something of the language you can do what you are looking for using my helper class above 🤝
[Image: jlscvfi.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pro_fesnoobSep 24, 2022 04:24 PM 14 796 Sep 24, 2022 04:24 PM
Last Post: BinaryFox
[C] by gurlhackerclubMay 19, 2020 05:18 PM 8 250 May 19, 2020 05:18 PM
Last Post: k1r3n
[C] by TralenSep 9, 2017 05:13 PM 7 207 Sep 9, 2017 05:13 PM
Last Post: 0xDEAD10CC