Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


November 28, 2007

Function Finds the nth Occurrence of Substrings

This VBScript function comes in handy when working with paths
RSS
View this exclusive article with VIP access -- click here to join |
See More Tips Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

 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. . . .

Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

How can I stop and start services from the command line?

...

Where is Microsoft NetMeeting in Windows XP?

...


Related Articles Use the FileToArray Function to Read a Text File Into an Array

Use the GetToken Function to Parse Delimited Lines

A VBScript Version of VBA’s IIf Function

Handle Strings More Easily

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing