SunQuest
 
       Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - VBScript: More String Functions
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 
Moblin 
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: More String Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-04-21

    Table of Contents:
  • VBScript: More String Functions
  • Left Behind
  • Right Ahead
  • The Middle Man
  • Left, Right, Mid…Using Them in a Stupid Way
  • Space() Not Really the Final Frontier After All

  • 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

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    VBScript: More String Functions - The Middle Man


    (Page 4 of 6 )

    The Mid() function is also used to parse data from a string. However, unlike the left() and right() functions, it doesn’t technically take from either side. By default, I suppose, it starts on the left side, however you have the option to decide at which position you want to begin taking data. For instance, you could have it start five characters in if you wanted. Here is an example showing Mid() in its default state:


    <html>

    <body>

    <script type="text/vbscript">

    ugly="Yo mama so ugly she made an onion cry"

    document.write(Mid(ugly,1))

    </script>

    </body>

    </html>

    This starts at position one, and prints the entire string:

      Yo mama so ugly she made an onion cry

    We can specify for it to start after the eighth position (remember to count spaces) like so:


    <html>

    <body>

    <script type="text/vbscript">

    ugly="Yo mama so ugly she made an onion cry"

    document.write(Mid(ugly,8))

    </script>

    </body>

    </html>

    Which gives us:

      so ugly she made an onion cry

    But what if we only want a certain number of characters? Say we want the first 10 characters. We would use the following code:


    <html>

    <body>

    <script type="text/vbscript">

    ugly="Yo mama so ugly she made an onion cry"

    document.write(Mid(ugly,1,10))

    </script>

    </body>

    </html>

    The first number, 1, tells us where to start. The number 10 tells us how many characters to grab:

      Yo mama so

    And of course if we wanted to grab fifteen characters but wanted to begin in position eight we would use this code:


    <html>

    <body>

    <script type="text/vbscript">

    ugly="Yo mama so ugly she made an onion cry"

    document.write(Mid(ugly,8,15))

    </script>

    </body>

    </html>

    Giving us:

      so ugly she ma

    Be careful not to set your beginning position to a number greater than the amount of characters in the string. Try out this code:


    <html>

    <body>

    <script type="text/vbscript">

    ugly="Yo mama so ugly she made an onion cry"

    document.write(Mid(ugly,100))

    </script>

    </body>

    </html>

    The result? A big fat nothing.

    More Windows Scripting Articles
    More By James Payne


       · Thanks for dropping by for another episode in our series on VBSCript String...
     

    WINDOWS SCRIPTING ARTICLES

    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - 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

    IBM developerWorks




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