Advertisement
Guest User

Untitled

a guest
Aug 15th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. /*Write a program for extracting all email addresses from given text.
  2.  All substrings that match the format <identifier>@<host>…<domain> should be recognized as emails.*/
  3. using System;
  4. using System.Text;
  5.  
  6. class ExtractingEmailAddressesFromAText
  7. {
  8.     static void Main()
  9.     {
  10.         string text = "using System; afasf@gmail.com,static void Main() extracting email!asfss@yahoo.com!";
  11.         StringBuilder reversedEmail = new StringBuilder();
  12.         StringBuilder realEmail = new StringBuilder();
  13.         for (int i = 0; i < text.Length; i++)
  14.         {
  15.             int counter = i;
  16.            
  17.             //I am getting the words before and after the sybol '@'
  18.             if (text[counter] == '@')
  19.             {
  20.                 while ((text[counter] != ' ') && (text[counter] != ',') && (text[counter] != '?') && (text[counter] != '!') && (text[i] != '[') && (text[counter] != ']') && (text[counter] != '{') && (text[counter] != '}') && (text[counter] != '+') && (text[counter] != '*') && (text[counter] != '=') && (text[counter] != '-'))
  21.                 {
  22.                     reversedEmail.Append(text[counter]);
  23.                     counter--;
  24.                 }
  25.                 for (int j = reversedEmail.Length - 1; j >= 0; j--)
  26.                 {
  27.                     realEmail.Append(reversedEmail[j]);
  28.                 }
  29.                 counter = i + 1;
  30.                
  31.                 while ((text[counter] != ' ') && (text[counter] != ',') && (text[counter] != '?') && (text[counter] != '!') && (text[i] != '[') && (text[counter] != ']') && (text[counter] != '{') && (text[counter] != '}') && (text[counter] != '+') && (text[counter] != '*') && (text[counter] != '=') && (text[counter] != '.'))
  32.                 {
  33.                     realEmail.Append(text[counter]);
  34.                     counter++;
  35.                 }
  36.                 realEmail.Append('.');
  37.                 counter++;
  38.                 while ((text[counter] != ' ') && (text[counter] != ',') && (text[counter] != '?') && (text[counter] != '!') && (text[i] != '[') && (text[counter] != ']') && (text[counter] != '{') && (text[counter] != '}') && (text[counter] != '+') && (text[counter] != '*') && (text[counter] != '=') && (text[counter] != '.'))
  39.                 {
  40.                     realEmail.Append(text[counter]);
  41.                     counter++;
  42.                 }
  43.                 Console.WriteLine(realEmail);
  44.             }
  45.             reversedEmail = new StringBuilder();
  46.             realEmail = new StringBuilder();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement