Results 1 to 6 of 6

Thread: How to split email string?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    How to split email string?

    If I had an email-

    [email protected]

    How would I split it so the end result would be

    firstnam.lastname?

    Thanks in advance everyone

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Re: How to split email string?

    Code:
      Dim Email As String = "[email protected]"
                Dim EmailStrSplit() As String = Email.Split(CChar("@"))
    
                MessageBox.Show(EmailStrSplit(0))

  3. #3
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: How to split email string?

    There are lots of great examples around the internet, just google "Split string" in vb.net

    Here is one great place to starthttp://www.homeandlearn.co.uk/net/nets7p7.html

    Code:
    'the text string you want to split up
            Dim LineOfText As String = TextBox1.Text
            'creates and array to store the differrent string parts
            Dim aryTextFile() As String
            'Set the character to split the string on
            aryTextFile = LineOfText.Split("@")
            'returns the first part of array
            MsgBox(aryTextFile(0))

    I hope this helps get you going

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to split email string?

    Quote Originally Posted by drawlings View Post
    [CODE]Dim EmailStrSplit() As String = Email.Split(CChar("@"))
    FYI, VB does have char literals: "@"C so you don't actually need the CChar conversion.
    Code:
    Dim emailParts() As String = email.Split("@"C)

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: How to split email string?

    Thanks everyone All of these are working. I did search on google, but it was a little confusing. These examples are much better : D

  6. #6
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Re: How to split email string?

    Quote Originally Posted by Joacim Andersson View Post
    FYI, VB does have char literals: "@"C so you don't actually need the CChar conversion.
    Code:
    Dim emailParts() As String = email.Split("@"C)
    True, forgot about that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width