Solved

split Email Address in C#

Posted on 2011-03-14
4
1,351 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Json POSt to Rest API 4 60
designing in object programming 12 75
How useful is the free version of Selenium? 3 31
SSRS subreport with parameter 3 29
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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