Skip to content

Instantly share code, notes, and snippets.

@SwipeX
Created April 5, 2016 18:07
Show Gist options
  • Save SwipeX/c3099cc4e66b6d3af75ae50bdacee6f8 to your computer and use it in GitHub Desktop.
Save SwipeX/c3099cc4e66b6d3af75ae50bdacee6f8 to your computer and use it in GitHub Desktop.
Imports System.IO
Imports System.Net
Public Class Form1
Dim _dictionary As New Dictionary(Of String, Integer)
Dim _ids As New Dictionary(Of String, Integer)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim pageContent As String = New System.Net.WebClient().DownloadString("C:\Users\timde\Downloads\names.json")
Dim split As String() = pageContent.Split("}")
For Each item As String In split
Dim values As String() = item.Split(":")
Dim idx = 0
Dim prev = ""
Dim id = 0
For Each trim As String In values
trim = RemoveCharacters({"{", "}", ",", ":", Chr(34)}, trim).Replace("store", String.Empty).Trim()
If idx = 0 And trim.Equals("") = False Then
id = Integer.Parse(trim)
ElseIf idx = 3 Then
If _dictionary.ContainsKey(prev) = False Then
_dictionary.Add(prev, Integer.Parse(trim))
_ids.Add(prev, id)
End If
End If
idx += 1
prev = trim.ToLower()
Next
Next
End Sub
Private Function RemoveCharacters(chars As Char(), input As String) As String
Return chars.Aggregate(input, Function(current, letter) current.Replace(letter, String.Empty))
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim input As String = TextBox1.Text.ToLower()
If (_dictionary.ContainsKey(input)) Then
Dim price As String = _dictionary.Item(input).ToString()
Dim id As String = _ids.Item(input).ToString()
Label1.Text = input & " price= " & price
Dim url = String.Format("http://cdn.rsbuddy.com/items/{0}.png", id)
Dim tClient = New WebClient()
Dim tImage As Bitmap = Image.FromStream(New MemoryStream(tClient.DownloadData(url)))
PictureBox1.Image = tImage
End If
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment