Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text
- Imports MaterialSkin
- Public Class Form1
- Public Function synonym(ByVal ord As String) As String
- Dim sourceString As String = New System.Net.WebClient().DownloadString("http://sproget.dk/lookup?SearchableText=" + ord)
- Dim stringSeparators() As String = {"<h3 id=""thesaurus"">Dansk Synonymordbog</h3><br />"}
- Dim split = sourceString.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
- Dim string_after = split(1)
- Dim mystr As String = string_after
- Dim cut_at As String = "</div>"
- Dim x As Integer = InStr(mystr, cut_at)
- Dim string_before As String = mystr.Substring(0, x - 2)
- Dim regex As New Text.RegularExpressions.Regex("<(.|\n)*?>")
- Dim result As String = regex.Replace(string_before, String.Empty)
- Dim final As String = result.Replace(",", Environment.NewLine)
- Dim entries As New List(Of String)()
- For Each line As String In final.Split(vbLf)
- line = String.Join(" ", line.Split(New Char() {}, StringSplitOptions.RemoveEmptyEntries))
- If line.Contains("Ã") OrElse line.Contains(";") OrElse line.Contains(":") OrElse line.Contains(">") OrElse line.Contains("<") OrElse line.Contains(" "c) Then
- Dim i = 0
- Else
- entries.Add(line)
- End If
- Next
- Dim builder As New StringBuilder()
- For Each i As Object In entries
- builder.AppendLine(i + ", ".ToString())
- Next
- Dim output As String = builder.ToString().Remove(0, 4)
- Return output.Remove(output.Length - 4)
- End Function
- Public Function rndsynonym(ByVal ord As String) As String
- Dim sourceString As String = New System.Net.WebClient().DownloadString("http://sproget.dk/lookup?SearchableText=" + ord)
- Dim stringSeparators() As String = {"<h3 id=""thesaurus"">Dansk Synonymordbog</h3><br />"}
- Dim split = sourceString.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
- Dim string_after = split(1)
- Dim mystr As String = string_after
- Dim cut_at As String = "</div>"
- Dim x As Integer = InStr(mystr, cut_at)
- Dim string_before As String = mystr.Substring(0, x - 2)
- Dim regex As New Text.RegularExpressions.Regex("<(.|\n)*?>")
- Dim result As String = regex.Replace(string_before, String.Empty)
- Dim final As String = result.Replace(",", Environment.NewLine)
- Dim entries As New List(Of String)()
- For Each thing As String In final.Split(vbLf)
- If thing.Contains("a") Then
- Dim i = 1
- Else
- entries.Add(thing)
- End If
- Next
- Dim rnd As New Random()
- 'Variable to hold our random line number
- Dim line As Integer
- 'Now we need a random number
- line = rnd.Next(entries.Count + 1)
- 'Now write out the random line to the TextBox
- Dim builder As New StringBuilder()
- builder.AppendLine(entries(line).Trim())
- Return builder.ToString().Replace(" ", "")
- End Function
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim SkinManager As MaterialSkinManager = MaterialSkinManager.Instance
- SkinManager.AddFormToManage(Me)
- SkinManager.Theme = MaterialSkinManager.Themes.LIGHT
- SkinManager.ColorScheme = New ColorScheme(Primary.Indigo500, Primary.Indigo700, Primary.Indigo100, Accent.Pink200, TextShade.WHITE)
- End Sub
- Private Sub MaterialRaisedButton1_Click(sender As Object, e As EventArgs)
- End Sub
- Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
- If PictureBox2.Visible = False Then
- PictureBox2.Visible = True
- Else
- PictureBox2.Visible = False
- End If
- End Sub
- Private Sub MaterialSingleLineTextField1_Click(sender As Object, e As EventArgs) Handles MaterialSingleLineTextField1.Click
- If MaterialSingleLineTextField1.Text = "Skriv noget.." Then
- MaterialSingleLineTextField1.Clear()
- End If
- End Sub
- Private Sub MaterialRaisedButton2_Click(sender As Object, e As EventArgs) Handles MaterialRaisedButton2.Click
- Try
- MaterialSingleLineTextField3.Text = synonym(MaterialSingleLineTextField4.Text)
- Catch ex As Exception
- MaterialSingleLineTextField3.Text = "Kunne ikke finde synonymer :("
- End Try
- End Sub
- Private Sub MaterialSingleLineTextField4_Click(sender As Object, e As EventArgs) Handles MaterialSingleLineTextField4.Click
- If MaterialSingleLineTextField4.Text = "Skriv noget.." Then
- MaterialSingleLineTextField4.Clear()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement