Solved

split Email Address in C#

Posted on 2011-03-14
4
1,422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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