Android Question Find Email Address In a string?

Discussion in 'Android Questions' started by aidymp, Mar 18, 2015.

  1. aidymp

    aidymp Active Member Licensed User

    Hi Im struggling a bit with this, basically I want to find an email address in a message body
    i have played with regex but thats not what is needed! As basically I want to search for an Email address in a string not validate one!

    I found this VB.net code here http://www.freevbcode.com/ShowCode.asp?ID=9434 and it sounds perfect but i cant convert it

    Code:
    Public Function FindEMailAddressesInStr(ByVal StringWithEmails As StringAs List(Of String)
        
    Dim emailList As New List(Of String)
        
    Dim RegExMatch As Text.RegularExpressions.MatchCollection = _
            System.Text.RegularExpressions.Regex.Matches(StringWithEmails, _
            
    "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")

        
    For i As Integer = 0 To RegExMatch.Count - 1
            
    If emailList.Contains(RegExMatch(i).Value) = False Then
                emailList.Add(RegExMatch(i).Value)
            
    End If
        
    Next

        
    Return emailList
    End Function
    Any Help

    Thanks
     
  2. NJDude

    NJDude Expert Licensed User

    Try THIS

    Also, search for Regex.Matcher.
     
    thedesolatesoul and aidymp like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Log(FindEmails($"aasd@sdsdf.com, lkjlk jsdf lksdjf
       fewfwe@gfgg.com"$
    ))
    End Sub

    Sub FindEmails(str As StringAs List
       
    Dim m As Matcher = Regex.Matcher("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", str)
       
    Dim res As List
       res.Initialize
       
    Do While m.Find
         res.Add(m.Match)
       
    Loop
       
    Return res
    End Sub
     
  4. aidymp

    aidymp Active Member Licensed User

    Thanks but from what i read that just validates if a sting contains a correctly formatted email address? not actually finds an email address in a large text file? But
    Thanks for your very fast response! ;)
     
  5. aidymp

    aidymp Active Member Licensed User


    Thanks once again Erel, Amazing! , Amazing! , Amazing! ;)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice