Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Location
    paris, FRANCE
    Posts
    88

    Question Unanswered: parsing query parametering part2

    hey!
    Up to now this function helps me to find within a field the words situated after the word "Keywords:". This is, to talk in a visual manner, the left limit of my parsing area.

    function:
    Public Function TheKeyWords(longText As String) As String
    Dim varPos As Variant
    varPos = InStr(1, longText, "Keywords:")
    If varPos > 0 Then
    TheKeyWords = Mid$(longText, InStr(1, longText, "Keywords:") + 9)
    Else
    TheKeyWords = ""
    End If
    End Function

    But being only a machine, my computer doesn't understand when the keywords stop. Due to an importing data problem, some words manage to get in the field keywords without being keywords.

    This non interesting part of the field always starts with the sentence "Partners already aquired". How could I, sort of like my left limit earlier, have this sentence be my right limit, but this limit being not included in the field?

    In other words, How could I tell my function that if it encounters "Partners already aquired" when searching through the field, it should stop and not give back this sentence as a result??
    thx to anyone who can help
    nico

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi nico,

    i don't think you are telling the full story in your post, but the following should solve the problem as posted:
    (i also got rid of the wasteful variant)
    (and the repeat of instr: you already determined varpos, and string-functions are inefficient so you don't want to repeat them if you can avoid it). edits are in gras

    Code:
    Public Function TheKeyWords(longText As String) As String
    Dim varPos As long 'instr returns a number
    Dim aString as string
    varPos = InStr(1, longText, "Keywords:")
      If varPos > 0 Then
        aString = Mid$(longText, varPos + 9) 'no need for the second instr
        if left$(aString,24) <> "Partners Already Aquired" then
          TheKeyWords = aString
        Else
          TheKeyWords = ""
        End If
      else
        TheKeyWords = ""
      endif
    End Function
    i just got back from a business trip - i see i got private-mail from you so i'll try to look at it sometime in the next few days.

    izy

  3. #3
    Join Date
    Apr 2003
    Location
    paris, FRANCE
    Posts
    88

    Talking

    hey IZy, nice to see you are always efficient!!
    I had to change a couple of things but using the skeleton of your code it works now. Here's the code I used for anyone who could have a similar problem...

    Code:
    Public Function StripKeywords(strInputString As String) As String
    
    'Does the phrase "Keywords:" exist in the string?
    If InStr(strInputString, "Keywords:") > 0 Then
    'if so, strip it out
    strInputString = Mid(strInputString, (InStr(strInputString, "Keywords:") + 9), Len(strInputString))
    Else: strInputString = ""
    GoTo ExitFunction
    End If
    
    'Does the phrase "Partners alredy acquired" exist in the string?
    If InStr(strInputString, "Partners already aquired") > 0 Then
    'if so, strip it out
    strInputString = Left(strInputString, (InStr(strInputString, "Partners already aquired") - 1))
    End If
    
    'Does the phrase ".Partners alredy acquired" exist in the string?
    If InStr(strInputString, ".Partners already aquired") > 0 Then
    'if so, strip it out
    strInputString = Left(strInputString, (InStr(strInputString, ".Partners already aquired") - 1))
    End If
    
    ExitFunction:
    StripKeywords = Trim(strInputString)
    
    End Function
    What do you think of this solution? Maybe there is a more efficient manner to do the task?
    Thanks again for your help!!!
    a bientot
    nico

Posting Permissions

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