Track the position of multiple occurences within a

Results 1 to 2 of 2

Thread: Track the position of multiple occurences within a

  1. #1
    Join Date
    Dec 1969

    Default Track the position of multiple occurences within a

    Due to the format of the records I am working with--it is neccessary to skip the first occurence of a word in a string and search for the position of the second. I then need to trim away everything before the second occurrence and proceed with my operation. Does anyone know of a way to do this?<BR>I have tried an INSTR() command and then assign a variable to the result. e.g. varcount=INSTR(varstring, "JOE") and then using the variable "varcount" as a starting point in another INSTR() command, but it seems to ignore the starting point. Any Help would be greatly appreciated.

  2. #2
    Join Date
    Dec 1969

    Default You have to move *PAST* first find...

    foundAt = INSTR( "THIS IS AN EXAMPLE", "IS" )<BR><BR>that will get you 3 as the value of foundAt, right?<BR><BR>Okay, so then you do:<BR><BR>foundAt = INSTR( foundAt, "THIS IS AN EXAMPLE", "IS" )<BR><BR>and you are really doing<BR><BR>foundAt = INSTR( 3, "THIS IS AN EXAMPLE", "IS" )<BR><BR>And the answer you get is... !! 3 !!<BR><BR>Well, after all, you *told* it to start there, so it did. And it found what you wanted.<BR><BR>So the answer is simple:<BR><BR>The second time around, do:<BR><BR>foundAt = INSTR( foundAt + 1, "THIS IS AN EXAMPLE", "IS" )<BR><BR>If you want to get more sophisticated, you should do:<BR><BR>foundAt = INSTR( foundAt + Len("IS"), "THIS IS AN EXAMPLE", "IS" )<BR><BR>[Reason: Suppose your search string is "TT" and the string contains "ABTTTCD". If you only move forward by 1, you&#039;ll find the second "TT" in the set of "TTT". Maybe that&#039;s what you want. But if not, move forward by the length of the search string.]<BR><BR><BR><BR>If you find "IS" at character 3 in "THIS IS AN EXAMPLE"

Posting Permissions

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