Announcement

Collapse
No announcement yet.

How to handle Quotes within VBS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to handle Quotes within VBS

    I've got a script parsing a webpage and am using the VBScript function Replace()to modify a few things. I know the syntax is:
    Webpage = Replace(Webpage,"Replace This","With This")
    But what do you do when the thing you are trying to replace has quotes in it? Such as replacing <hspace="23"> with <hspace"7">. I've tried double quoting but the " in what I'm searching for or trying to replace generates an error. How do you handle this?

    #2
    Hi d-smes,

    One way is to break the string apart and use character codes. How 'bout something like this?

    sub main()

    webpage = "<hspace=""23"">"

    'this will display <hspace="23">
    msgbox webpage

    'seperate strings and use character codes for quotes
    replacethis = "<hspace=" & chr(34) & "23" & chr(34) & ">"
    withthis = "<hspace=" & chr(34) & "7" & chr(34) & ">"

    webpage=Replace(webpage,replacethis,withthis)

    'and now this will display <hspace="7">
    msgbox webpage

    end sub

    Does that help?

    Joe
    HomeSeer Rocks!

    Comment


      #3
      I just tried a test and it worked....

      sub main()

      test = "This is a ""test"""

      test = replace(test, """", "a")

      hs.writelog "test", test

      end sub

      The log showed:

      This is a atesta

      Patrick Sikes
      SikesCentral Home Automation
      patsikes@sikescentral.com
      mobile@sikescentral.com (180 char max)

      Comment


        #4
        Yes, it all makes sense and works!
        Thanks again!

        Comment

        Working...
        X