BorislavBorisov

Task.Extract URLs from Text

Oct 9th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. class URLs
  3. {
  4.     static void Main()
  5.     {
  6.         string texiInput = "The site nakov.com can be access from http://nakov.com or www.nakov.com. It has subdomains like mail.nakov.com and svetlin.nakov.com. Please check http://blog.nakov.com for more information.";
  7.  
  8.         FindURL(texiInput);
  9.     }
  10.     static void FindURL(string textInput)
  11.     {
  12.         for (int i = 0; i < textInput.Length; i++)
  13.         {
  14.             if((textInput[i] == 'h' && textInput[i + 4] == ':')
  15.                 || (textInput[i] == 'w' && textInput[i + 1] == 'w' && textInput[i + 3] == '.'))
  16.             {
  17.                 while(true)
  18.                 {//за да избегна точката накрая
  19.                     if (textInput[i] == '.' && textInput[i + 4] == ' ')
  20.                     {
  21.                         break;
  22.                     }
  23.                     Console.Write(textInput[i]);
  24.                     i++;
  25.                 }
  26.                 Console.WriteLine();
  27.             }
  28.         }  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment