We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 10,519 times

Contents

    An Introduction to String Handling in VB6 - Left, Mid and Right

    sync_or_swim

    Left, Mid and Right

    Splitting a String at Specific Points Using Left, Mid and Right

    We saw that the Split function can chop up a string and create an array of the individual components.  The Left, Mid and Right functions are useful for extracting specific information from a given string

    Syntax
    Left(String, Position)
    Mid(String, Position)
    Right(String, Position)

    Return Value
    The left function will return all characters to the left of a specified point within a string
    The Mid function will return all characters to the right of a specified point within a string
    The Right function will return the specified number of rightmost characters from a given string

    Usage
    These functions may be used in conjunction with InStr to locate substrings within a given string and chop up the original string to "dig out" a specified string.  For Example, imagine we used the example above to recover the filename from the full path, we can recover just the file extension using the Right function:

    Dim strFileExtension As String
    strFileExtension = Right(strFileName, 3)
    or we can remove the file extension to leave just the filename by calculating the position of the full stop, note that it is necessary to use the -1 because InStr(1, strFileName, ".") would include the full stop in the filename as well 

    strFileName = Left(strFileName, InStr(1, strFileName, ".") - 1)
    This is only an example, in the real-world you would probably use the FSO to accomplish this, it was only intended as a demonstration of how strings may be chopped of at specific points.

    Comments