Question

Is there any level of support for, or an alternative to, heredoc syntax in vbscript? I have the following:

test = "an "example" string"

where the actual contents of the string (i.e. an "example" string) is inserted via a separate technology level (pretend its similar to a macro preprocessor) and there may be no way around that. So, ideally, I'd like something like:

test = <<<EOL
    an "example" string
EOL;

but vbscript doesn't, as far as I can tell, support heredoc syntax. Any alternatives?

Was it helpful?

Solution

@Bobby Jack: The best I can come up with is importing a file which contains all the formatting/other data you need, e.g.

    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    Set oF  = oFS.OpenTextFile(Server.MapPath("somefile.html"), 1)
    sText   = oF.ReadAll
    oF.Close
    Set oF  = Nothing
    Set oFS = Nothing

And then replacing "variables" within it that are delimited by some characters, e.g.:

    sText = Replace(sText, "##var1##", var1)
    sText = Replace(sText, "##var2##", var2)
    sText = Replace(sText, "##var10##", var10)

sText can then be saved to another file or output to the screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top