Solved

split Email Address in C#

Posted on 2011-03-14
4
1,322 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
Comment Utility
     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
Comment Utility
to get only first part try
Console.WriteLine(words[0]);
0
 
LVL 6

Assisted Solution

by:nandithaa
nandithaa earned 166 total points
Comment Utility
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
Comment Utility
Remember the array is 0 based so
result[0]= will.smith.

result[1] = gmail.com


0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

11 Experts available now in Live!

Get 1:1 Help Now