开发者

How to use substring in vbscript within a xsl page

开发者 https://www.devze.com 2023-01-04 02:59 出处:网络
I am trying to replace the double quotes in a string with a single quote, got the following code but get error message saying \"Object Required strLocation\"

I am trying to replace the double quotes in a string with a single quote, got the following code but get error message saying "Object Required strLocation"

Sub UpdateAdvancedDecisions(strLocation)
  Dim d
  Dim strLLength

  strLLength = Len(strLocation) - 1

  For d = 0 To strLLength
    alert strLocation

    strValue = strLocation.Substring(2,3)

    If strLocation.substring(d,d+1)=" " " Then   
      strLLength = strLLength.substring(0, d) + "'" + strLLength.substring(d + 1,strLLength.length)

  Ne开发者_C百科xt
End Sub


As Helen said, you want to use Replace, but her example assigned the result to your weird strLLength variable. Try this instead:

strLocation = Replace(strLocation, """", "'")

This one line does the job you asked about and avoids all the code currently in your given subroutine.

Other things that are problems in the code you posted:

  • a variable holding a number like the length of a string would not have a "str" prefix, so strLLength is misleading

  • strings in VBScript are indexed from 1 through length, not 0 through length-1

  • there is no "alert" keyword in VBScript

  • you assign a value to strValue, then never use it again

  • you need to use Mid to get a substring, there is no "substring" string method in VBScript

    c = Mid(strLocation, d, 1) ' gets one character at position d
    

The more I look at this, the more clear it is that its some JavaScript that you're trying to run as VBScript but are not translating at all correctly.

Use a reference for VBScript like one of the following:

  • MSDN Library: VBScript Language Reference
  • W3Schools VBScript Tutorial
0

精彩评论

暂无评论...
验证码 换一张
取 消