Advertisement
RaWRCoder

Getting html title from aiondatabase.net

Aug 6th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1.     private void button8_Click(object sender, EventArgs e)
  2.         {
  3.             var wc = new WebClient{Encoding = Encoding.UTF8};
  4.             wc.DownloadStringCompleted += ObtainItemName;
  5.             wc.DownloadStringAsync(new Uri(uiURL_Items.Text));
  6.         }
  7.  
  8.         static int titlelen = "<title>".Length;
  9.         private void ObtainItemName(object sender, DownloadStringCompletedEventArgs e)
  10.         {
  11.             if (e.Error != null)
  12.             {
  13.                 MessageBox.Show(e.ToString(), "Exception while loading file");
  14.                 return;
  15.             }
  16.             var s = e.Result.Split('\n');
  17.             var r = "<error>";
  18.             if (s.Length < 4)
  19.             {
  20.                 uiResult_Items.Text = r;
  21.                 return;
  22.             }
  23.             var line = s[3];
  24.             line = line.Remove(0, titlelen);
  25.             var id = line.IndexOf(" - Aion", StringComparison.Ordinal);
  26.             line = line.Remove(id);
  27.             if (string.IsNullOrWhiteSpace(line))
  28.             {
  29.                 uiResult_Items.Text = r;
  30.                 return;
  31.             }
  32.             r = line;
  33.             uiResult_Items.Text = r;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement