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

前端 未结 4 848
温柔的废话
温柔的废话 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.

    0 讨论(0)
  • 2020-12-11 01:56

    You can use

    MyString = Mid(First_String, 5)
    
    0 讨论(0)
  • 2020-12-11 02:07

    Try this (just create sample.vbs with this content):

    Option Explicit
    
    Dim sText
    
    sText = "aaaaString"
    sText = Right(sText, Len(sText) - 4)
    
    MsgBox(sText)
    
    0 讨论(0)
  • 2020-12-11 02:09

    I request you to use the following script to strip first 4 characters of your string StringName = Mid(StringName,5)

    0 讨论(0)
提交回复
热议问题