Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Parse subject heading of email in VB.NET

  • 31-05-2006 12:24PM
    #1
    Registered Users, Registered Users 2 Posts: 4,326 ✭✭✭


    I have a VB.NET application that checks the subject of each email in my inbox and moves it to another folder if it contains 3 words at the very end of the heading.
    I don't think I can just put in an if statement to check this, I have to parse it?


Comments

  • Registered Users, Registered Users 2 Posts: 684 ✭✭✭Gosh


    Use
    IF UCase(Instr(subject, "WORD-1")) <> 0 Or UCase(Instr(subject, "WORD-2)) <> 0 Or UCase(Instr(subject, "WORD-3")) <> 0 Then
    
     ' Do Something if any of the words exist
    
    END IF
    
    Note "WORD-1", "WORD-2", "WORD-3" must be in capitals


  • Registered Users, Registered Users 2 Posts: 4,326 ✭✭✭lukin


    I probably didn't explain myself very well:the heading must contain three certain words, not just any three words.


  • Registered Users, Registered Users 2 Posts: 4,326 ✭✭✭lukin


    Think it's OK now.

    I just used substring instead and then used the ".Length" function to grab them.
    The three words I want to find in the heading are 21 letters long in total (sorry I can't tell you what they are!)

    I check to see if the heading is greater than 21 words and also if a substring of it which is 21 letters from the end contains the words I want
    If (strHeading.Length > 21) And (strHeading.Substring(strHeading.Length - 21, 21)) = "3 words I want go here" Then
    //do whatever
    


  • Registered Users, Registered Users 2 Posts: 684 ✭✭✭Gosh


    Another way is to split the subject and check each word ...
    Private Sub CheckSubjectLine(ByVal EmailSubject As String)
    
    Dim SplitSubject() As String = EmailSubject.Split(" "c)
    
       For Each s As String In SplitSubject
          Select Case UCase(s)
              Case "WORD-1", "WORD-2", "WORD-3"
                 ' do something here
           End Select
        Next
    
    End Sub
    


    Or, in your case, if you know it's always at the end then use ...
    Select Case UCase(Microsoft.VisualBasic.Right(EmailSubject, 21))
       Case "WORD-1", "WORD-2", "WORD-3"
          ' do domething here
    End Select
    


  • Registered Users, Registered Users 2 Posts: 1,454 ✭✭✭Smoggy


    Lukin, yours just checks the last 21 chars , does this mean that your 3 words are of fixed length ?


  • Advertisement
Advertisement