Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Parse subject heading of email in VB.NET

  • 31-05-2006 11:24am
    #1
    Registered Users, Registered Users 2 Posts: 4,114 ✭✭✭


    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: 683 ✭✭✭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,114 ✭✭✭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,114 ✭✭✭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: 683 ✭✭✭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,466 ✭✭✭Smoggy


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


  • Advertisement
Advertisement