Solved

split Email Address in C#

Posted on 2011-03-14
4
1,340 Views
Last Modified: 2012-05-11
Hi

Any one help me am trying to split this string based on '@' Level

String: Will.Smith@Gmail.com
am trying to split this string in '@" level and
grab the first part

String[1]= will.smith.

string= will.smith@gmail.com
string[] stringSeparators = new string[] { "@"};
string[] result;

 result = subStringString.Split(stringSeparators, StringSplitOptions.None);

        foreach (string str in result)

        {

            Console.WriteLine(str);

        }

        Console.WriteLine("=======================================");

Open in new window


0
Comment
Question by:Sha1395
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 167 total points
ID: 35135399
     string s = "will.smith@gmail.com";
                        string[] words = s.Split('@');
                  foreach (string word in words)
                  {
                        Console.WriteLine(word);
                  }
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35135404
to get only first part try
Console.WriteLine(words[0]);
0
 
LVL 6

Assisted Solution

by:nandithaa
nandithaa earned 166 total points
ID: 35135413
Is this what u want?
            string subStringString = "will.smith@gmail.com";
            string[] stringSeparators = new string[] { "@" };
            string[] result;

            result = subStringString.Split(stringSeparators, StringSplitOptions.None);
            Console.WriteLine(result[0]..ToString());
             Console.WriteLine("=======================================");
                
           

Open in new window

0
 
LVL 7

Assisted Solution

by:mkobrin
mkobrin earned 167 total points
ID: 35135417
Remember the array is 0 based so
result[0]= will.smith.

result[1] = gmail.com


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# application error "Parameter Is Not Valid". 3 80
Two different visual studio versions 3 23
SQL Login 17 40
How useful is the free version of Selenium? 3 16
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now