Reputation: 4923
How do I use VBScript to strip the first four characters of a string?
So that the first four characters are no longer part of the string.
Upvotes: 15
Views: 90908
Reputation: 49
I request you to use the following script to strip first 4 characters of your string StringName = Mid(StringName,5)
Upvotes: 2
Reputation: 200293
You have several options, some of which have already been mentioned by others:
Use a regular expression replacement:
s = "abcdefghijk"
n = 4
Set re = New RegExp
re.Pattern = "^.{" & n & "}" 'match n characters from beginning of string
result = re.Replace(s, "")
Use the Mid
function:
s = "abcdefghijk"
n = 4
result = Mid(s, n+1)
Use the Right
and Len
functions:
s = "abcdefghijk"
n = 4
result = Right(s, Len(s) - n)
Usually string operations (Mid
, Right
) are faster, whereas regular expression operations are more versatile.
Upvotes: 6
Reputation: 4434
Try this (just create sample.vbs with this content):
Option Explicit
Dim sText
sText = "aaaaString"
sText = Right(sText, Len(sText) - 4)
MsgBox(sText)
Upvotes: 2