vbScript - Some Useful String Functions
Please see my post vbScript - The Basics for more details on vbScript.
vbScript provides a number of functions for manipulating strings. I find that a few more simple functions would have made things a lot simpler. For example, I find myself checking to see if a string starts with a given string. What I have to code is
If len(str1) < len(str2) Then
StartsWith = False
Else If Left(str1,len(str2)) = str2 Then
StartsWith = True
Else
StartsWIth = False
End If
It would be much clearer if I could do
If StartsWith(str1,str2) Then
Similarly, I will frequently drop characters from the beginning or end of a string. This can result in some convoluted calculations inside calls to Left
, Right
, and Mid
. Whenever I need a string function I code it up once and add it to my StrFuncs.vbs
include file. They are detailed here. See the comments in the code snippet for details.