Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that extracts and prints all URLs from given text.
- namespace _15.ExtractURLsFromText
- {
- using System;
- public class ExtractURLsFromText
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.WriteLine("Enter your Text on single line!");
- string inputText = Console.ReadLine();
- char[] separators = new char[] { ' ', ',', ';' };
- string[] text = inputText.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- if (text.Length > 0)
- {
- Console.WriteLine("The URLs in Given Text are:");
- for (int i = 0; i < text.Length; i++)
- {
- string word = text[i];
- bool isWebSite = word.Contains("http://") || word.Contains("www.");
- if (isWebSite)
- {
- Console.WriteLine(word);
- }
- }
- }
- else
- {
- Console.WriteLine("Error! - Invalid Input!!!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement