Advertisement
redSkywalker

класс

Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Converter
  9. {
  10.     class WebManager
  11.     {
  12.         public string ConnectionAndSearch(string _moneyType)
  13.         {
  14.             string Money_course = "";
  15.             string pattern = "";
  16.             System.Net.WebClient wc = new System.Net.WebClient();
  17.             string Response = wc.DownloadString("http://www.finmarket.ru/currency/rates/");
  18.             if(_moneyType.Equals("euro"))
  19.             {
  20.                 pattern = @"EUR</div><div class=""value"">(\d*,\d*)";
  21.             }
  22.             else if (_moneyType.Equals("dollar"))
  23.             {
  24.                 pattern = @"USD</div><div class=""value"">(\d*,\d*)";
  25.             }
  26.             else if (_moneyType.Equals("funt"))
  27.             {
  28.                 pattern = @"GBP</div><div class=""value"">(\d*,\d*)";
  29.             }
  30.            
  31.  
  32.             MatchCollection matches = Regex.Matches(Response, pattern);
  33.             if (matches.Count > 0)
  34.             {
  35.                 foreach (Match match in matches)
  36.                     Money_course = match.Groups[1].Value;
  37.             }
  38.  
  39.            
  40.             return Money_course;
  41.         }
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement