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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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


    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

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT