Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

split Email Address in C#

Posted on 2011-03-14
4
Medium Priority
?
1,572 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 668 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 664 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 668 total points
ID: 35135417
Remember the array is 0 based so
result[0]= will.smith.

result[1] = gmail.com


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

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