Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - 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 
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: 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

    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: More String Functions - Left, Right, Mid…Using Them in a Stupid Way


    (Page 5 of 6 )

    You can use Left, Right, and Mid all together if you like, though it might not really be all that practical. Still here is some mind numbing code:


    <html>

    <body>

    <script type="text/vbscript">

    dim subliminal

    subliminal="Kick that ball will you? Do it yourself!"

    document.write(Left(subliminal,1))

    document.write(Mid(subliminal,17,3))

    document.write(Right(subliminal,10))

    </script>

    </body>

    </html>

    In the above code I gave the variable “subliminal” a normal looking value; two sentences you might hear some kids shouting on the playground. However, once you insert my sneaky code and run the program, something else entirely happens…the result:

      Kill yourself!

    Len()ding Yourself a Hand

    The Len() function is used to tell you how many characters are in a string. An easy way to remember the Len() function is to think of the word length, from which the function name is derived. Here it is in use:


    <html>

    <body>

    <script type="text/vbscript">

    document.write(Len("He-Man should really purchase himself a pair of pants."))

    </script>

    </body>

    </html>

    This counts the amount of characters in our string and displays it:

      54

    We can, of course, do the same thing with variables:


    <html>

    <body>

    <script type="text/vbscript">

    goodidea="He-Man should really purchase himself a pair of pants."

    document.write(Len(goodidea))

    </script>

    </body>

    </html>

    Giving us the same result as before:

      54

    Though it might seem redundant, you can also use the Len() function in conjunction with the Right() and Left() functions:


    <html>

    <body>

    <script type="text/vbscript">

    goodidea="He-Man should really purchase himself a pair of pants."

    a=Len(goodidea)

    document.write(Len(goodidea)) & "<br />"

    document.write(Left(goodidea,a)) & "<br />"

    document.write(Right(goodidea,a)) & "<br />"

    </script>

    </body>

    </html>

    This code puts the length of the string in the variable “a,” then tells first the left, then the right, how many characters to print from the string. Since we used Len(), it tells them to print all 54 characters. Here is the result of this code:

     54
      He-Man should really purchase himself a pair of pants.
      He-Man should really purchase himself a pair of pants.

    More Windows Scripting Articles
    More By James Payne


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

    WINDOWS SCRIPTING ARTICLES

    - 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
    - Moving and Renaming Computers with Active Di...





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