How Do I Use VBScript to Strip the First n Characters of a String?

前端 未结 4 850
温柔的废话
温柔的废话 2020-12-11 01:45

How do I use VBScript to strip the first four characters of a string?

Ss that the first four characters are no longer part of the string.

4条回答
  •  死守一世寂寞
    2020-12-11 01:53

    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.

提交回复
热议问题