Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - VBScript: Functioning with Strings
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

VBScript: Functioning with Strings
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-04-14

    Table of Contents:
  • VBScript: Functioning with Strings
  • Checking If It’s In With the InStr() Function
  • Using InStr() with Variables
  • Uppercase and Lowercase

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    VBScript: Functioning with Strings - Using InStr() with Variables


    (Page 3 of 4 )

    You can also test to see whether or not the value in a variable is in a string and have it print the position where the value begins, like so:


    <html>

    <body>

    <script type="text/vbscript">

    dim ape

    dim toon

    dim where

    toon="George, George, George of the jungle."

    ape="the"

    where=InStr(1,toon,"o",0)

    document.write(where) & "<br />"

    where=InStr(toon,ape)

    document.write(where)

    </script>

    </body>

    </html>

    This code will result in:

      3

      27

    Working with the InStrRev() Function

    As you can imagine, the InStrRev() function works like the InStr() function, only in reverse. It begins searching from the end of the string and works its way to the front. Here are some examples showing how it works:

    <html>

    <body>

    <script type="text/vbscript">

    dim gump,where

    gump="Ugly is as ugly does"

    where=InStrRev(gump,"ugly")

    document.write(where)

    </script>

    </body>

    </html>

    The result of this code is:

      12

    If we had used the InStr() function, it would have found the first instance of the word “ugly” at position 1, or at the beginning of the string. However, with the InStrRev() function, we begin searching at the end of the string and thus, find the first occurrence of “ugly” at position 12 instead.

    And just as you can specify the location for the search to begin with InStr(), so too can you using InStrRev:


    <html>

    <body>

    <script type="text/vbscript">

    dim gump,where

    gump="Ugly is as ugly does"

    where=InStrRev(gump,"ugly",19)

    document.write(where)

    </script>

    </body>

    </html>

    Here, we begin the search at the nineteenth position and we again find the first occurrence of “ugly” at position 12.

    More Windows Scripting Articles
    More By James Payne


       · You should have included the LIKE function. This function gives developers a...
       · Hey, thanks for the suggestion. I'll actually be doing an article on regex soon, and...
     

    WINDOWS SCRIPTING ARTICLES

    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...
    - Working with System Processes in WSH





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway