Page

4.7.4- Removing the Middle of a String

  by NT Community Manager.  

PublicCategorized as 04. Variables.

Not tagged.
<< 4.7.3- Pruning the Beginning or End of a StringChapter44.7.5- Finding a Particular Word >>

Removing the Middle of a String

Of course, that leaves the problem of extracting a section from the middle of a string. To do this, VBScript provides another function, Mid. The function Midworks along the same principles as Right and Left, but it takes an extra parameter:

 

Mid(string, where_in_the_string, number_of_characters_to_be_extracted)

 

Once again, the first parameter is the source string itself. The second parameter is the position of the first character in the substringthat you want to extract, and the third is the number of characters in thesubstring. In our little example, we can isolate the word "Piece" by setting the second parameter to 11(corresponding to the letter "P") andthe third parameter to 5 (indicating the number of characters in the desiredsubstring). The following example extracts the word "Piece"from our original string, and assigns it to the variable strMiddleChars:

 

strText = "HowLongIsAPieceOfString?"

strMiddleChars = Mid(strText,11,5)

<< 4.7.3- Pruning the Beginning or End of a StringChapter44.7.5- Finding a Particular Word >>

Copyright © 2003 by Wiley Publishing, Inc.

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