Web Development

  Homes arrow Web Development arrow Parsing strings in ASP using VBscript
 Webmaster Tools
 
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML to PHP 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
 
Password Strength
 
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB DEVELOPMENT

Parsing strings in ASP using VBscript
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 22
    2004-05-20

    Table of Contents:

    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
     
     

    SEARCH DEV MECHANIC

    TOOLS YOU CAN USE

    advertisement


    by: Codefixer.com

    Parsing strings in ASP using VBscript

    Below are some of the more common functions which help us manipulate strings.

    InStr()

    Syntax: InStr(StringToSearch, StringToFind)
    The Function will return the position of the first occurence of StringToFind within StringToSearch
    The Function will return 0 if StringToFind is not found.

    Example 1:

    <%
    String1="michael"
    String2="wall"
    If InStr(String1,String2)>0 Then
    Response.write("String1 contains String2")
    Else
    Response.write("String1 is not in String2")
    End if
    %>



    Example 2:

    <%
    String1="It's taken me 4 years of work"
    String2="t"
    Location= Instr(String1,String2)
    response.write Location
    %>

    Result displayed on the screen would be:
    2

    Note you can set the starting position for each search. If omitted, search begins at the first character position.

    Example 3:

    <%
    String1="It's taken me 4 years of work"
    String2="t"
    Location= Instr(3,String1,String2)
    response.write Location
    %>

    Result displayed on the screen would be:
    6



    Left()

    Syntax: Left(String, NumofCharactersToGetFromString)
    The Function will return the number of characters you stipulate. As is obvious it starts from the left.

    Example:

    <%
    String1="michael"
    response.write("the first 3 letters of my name are " & Left(String1,2))
    %>


    Result displayed on the screen would be:
    mic
    The reason being that the first 3 letters of my name are mic

    Remember here that the first character is indexed at 0 so in the above example m is character 0 and c is character 2.



    Right()

    As you can imagine right do something very similar to left, though it starts from the right.


    Len()

    Syntax: Len(String)
    The function will simply return the length of the string.

    Example1:

    <%
    String1="michael"
    Response.write Len(String1)
    %>


    Result displayed on the screen would be:
    7

    * Remember that for the length function the first character has a 1 index.

    Example2:

    <%
    String1="michael"
    Response.write Left(String1,Len(String1)-4)
    ' what the above code is doing is getting the length of the string michael, which is 7
    'and taking 4 away leaving us with a string of the first 3 characters from the left.

    %>


    Result displayed on the screen would be:
    mic


    Replace()

    The Replace function can be used to replace certain characters within a string with other characters.

    Syntax: Replace(StringToSearch, StringToFind, ReplaceWithThisString)

    StringtoSearch is the string you want to check for any occurence of the StringToFind. If there are any occurences of StringToFind then the function will replace them with ReplaceWithThisString. Every occurence will be replaced starting from the first character of StringToSearch.

    Example:
    <%
    String1="My_Name_is_Michael"
    Response.write (Replace(String1,"_"," "))
    %>

    Result displayed on the screen would be:
    My Name is Michael


    LCase(), UCase()

    You can use LCase() and UCase() to pass in the string variable and thus convert the string into either uppercase or lowercase.

    Example 1:

    <%
    myName = "MICHAEL"
    Response.Write(LCase(myName))
    %>


    Result displayed on the screen would be:
    michael

    Example2:

    <%
    myNAME = "michael"
    Response.Write(UCase(myName))
    %>


    Result displayed on the screen would be:
    MICHAEL


    Mid()

    syntax: Mid(StringtoPullFrom, CharactertoStartWith, LengthofCharactersToPull)

    The Function will return the requested number of characters from a string.
    The LengthofCharactersToPull parameter is optional. If LengthofCharactersToPull is left out, Mid will return all of the characters starting from CharacterToStartWith.

    Example:

    <%
    String1="michael"
    Response.write Mid(String1,3,3)
    %>

    Result displayed on the screen would be:
    cha

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed

       

    WEB DEVELOPMENT ARTICLES

    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates

     



    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap