Results 1 to 7 of 7

Thread: [RESOLVED] How to Retrieve Email Address from a String With Same Username

  1. #1

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Resolved [RESOLVED] How to Retrieve Email Address from a String With Same Username

    I would like to Retrieve All Email Addresses from String, that contains the same Username.

    For Example: The Usernames are in Green Color and Emails in DarkRed below.

    1) 1, 2, Mick, Mick@yahoo.com, 3, 4, 5,
    2) 1, 2, Test, Test@yahoo.com, 3, 4, 5,
    3) 1 ,2, Allen, SomeUser@yahoo.com, 3, 4, 5,

    I need to get the Email Addresses from the first two lines where the USername is same as the Email Addresses. While the 3rd line has a different email.

    So how can I get the Emails of the first two lines and ignore the rest?

    I created a Regex Sample, But I am only able to get the Usernames. Hope I could get some help.

    Code:
        Private Sub GetDuplicates()
            Dim input As String = txtResults.Text
            Dim pattern As String = ","
            Dim substrings() As String = Regex.Split(input, pattern)
            For Each match As String In substrings
                ListBoxDuplicatesCheck.Items.Add(match.ToLower)
                Dim textToSearch As String = LCase(match)
                If textToSearch.Contains("@") Then RichTextBox1.AppendText(textToSearch & vbCrLf)
                For Each item In ListBoxDuplicatesCheck.Items
                    If isNameInList(item.ToString.ToLower) = True AndAlso Not item.ToString.Contains("@") Then
                        ListBox1.Items.Add(item.Replace(",", ""))
                    End If
                Next
            Next
            RepoveDuplicate()
        End Sub

    Thank you in advance.


    Last edited by Miklogak; Mar 9th, 2018 at 03:10 PM.

    A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: How to Retrieve Email Address from a String With Same Username

    Try this...

    Code:
    Dim lines() As String = txtResults.lines
    Dim emailAddresses() As String = lines.Where(Function(l) l.Split(New String() {", "}, StringSplitOptions.None)(3).StartsWith( _
                                                            l.Split(New String() {", "}, StringSplitOptions.None)(2) & "@")).Select(Function(l) _
                                                            l.Split(New String() {", "}, StringSplitOptions.None)(3)).ToArray

  3. #3

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Re: How to Retrieve Email Address from a String With Same Username

    @Paul, Thank you so much. You are litteraly a Life Saver. I have used almost 72 hours on this but couldn't get anywhere! Now it worked perfect.

    EDIT 1, BTW. Dear Paul. The code works perfectly on those 3 lines. But I got and error when adding more lines. What do I do to cover all of the lines?

    EDIT 2: Ok I made it work now. I found out It was because the empty lines inside the richtextbox that caused an index Errror. TY AGAIN

    @Rated...
    Last edited by Miklogak; Mar 7th, 2018 at 05:23 PM.

    A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: How to Retrieve Email Address from a String With Same Username

    how can paul answer this when ll you did was post the three lines? he cant read minds

  5. #5

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Re: How to Retrieve Email Address from a String With Same Username

    @ident, Please read the edited comment
    Last edited by Miklogak; Mar 7th, 2018 at 05:25 PM.

    A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: How to Retrieve Email Address from a String With Same Username

    Excuse me? I have read every post during multiple changes of editing. You edited at 10.15 i posted at 10.14. It's not great you being rude since i have helped you on a number of occasions. I was going to offer a number of changes to your first post of code since it's written quite poorly. But i wont now. I'm not saying that as being rude but you want to edit your posts constantly then dont expect members to offer advice. Most members wont.

    Yes you changed your post again with a smiley.

  7. #7

    Thread Starter
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    203

    Re: How to Retrieve Email Address from a String With Same Username

    @Ident. First of all you dont have to speak or chat with an attitude. I was asking a question and was not trying to be rude. But then you came off very rude and with a negatives attitude! And yes as for your help 2-3 years ago. I did thank you. I dont owe you nothing. You dont owe me anything.

    Your attitude is what matters. You come with bad attitude, what you expect to get in return? Have blessed day.

    A huge thanks to all the Great Developers and Helpers on vBForums for helping me and many others! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident for helping me with my projects througout the years. Incl. those i forgot to mention!

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