Executive Summary:
| Although VBScript offers the InStr and InStrRev functions to find the position of a substring, they only find the position of the substring's first occurrence. Sometimes, you might need to find the position of a different occurrence, such as the second or fourth occurrence of the substring. If you find yourself in this situation, you can use the nInStr function. This user-defined VBScript function lets you find the starting position of any occurrence of a substring. |
Creating a function that finds the nth occurrence of a substring is one of those things I said I’d do someday but had never found the time to do. Because necessity is the mother of invention, "someday" actually arrived when I was recently confronted with a text file full of pathnames that pointed to files I needed to copy. I had to copy the files from a folder on one server to a folder with the same name on another server, then delete the original folder and its contents. . . .

