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  
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: More String Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    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


    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

    - 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek