Page

4.7.3- Pruning the Beginning or End of a String

Created by Brendan Doss.
Last Updated by Brendan Doss.  

PublicCategorized as 04. Variables.

Not yet tagged
<< 4.7.2- Returning the Length of a StringChapter44.7.4- Removing the Middle of a String >>

Pruning the Beginning or End of a String

The Left and Right Functions can be used to extract a given numberof characters from the beginning or end of a given string. They don't actually'remove' the characters as such; instead, they act like the 'Copy' function ofa word processor and copy the selected section into the new variable. Each ofthese functions takes two parameters:

 

Left(string, number_of_characters)

 

And

 

Right(string, number_of_characters)

 

The Left function's second parameter, number_of_charactersspecifies how many characters to extract from the beginning (left-hand side) ofthe string:

 

strLeftChars =Left("HowLongIsAPieceOfString?",3)

 

StrLeftChars would contain thestring "How". Again, you can alsosupply a variable name to the Left function,which will extract the appropriate substring from the string contained by thisvariable. For example:

 

strText = "HowLongIsAPieceOfString?"

strLeftChars = Left(strText,7)

 

This would assign the string "HowLong"to the variable strLeftChars.

 

The Right function works inthe same way, except that it extracts characters from the (right-hand) end ofthe string:

 

strRightChars =Right("HowLongIsAPieceOfString?",7)

 

Here, the variable strRightCharsis assigned the string "String?".Again, this function supports the option of extracting characters from a stringvariant; and once again, symbols, spaces, and punctuation count as validcharacters.

<< 4.7.2- Returning the Length of a StringChapter44.7.4- Removing the Middle of a String >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |