Development‎ > ‎VBScript‎ > ‎

Converting text to VBScript string

Very often when prepering an automated test or utility script there is a need for converting command line text or expected message into VBScript string format.

Following is a simple procedure which I use every time I need to convert text into a format understandable by VBScript.
  1. Define the text which needs converting into VBScript string format

  2. "dynamic string one" /r "dynamic string two" "dynamic string three"

  3. Replace any quote character in your source text with two quotes

    ""dynamic string one"" /r ""dynamic string two"" ""dynamic string three""

  4. Surround the expression with quotes

    """dynamic string one"" /r ""dynamic string two"" ""dynamic string three"""

  5. Replace the dynamic parts of the string e.g.  [dynamic string one] with variable [" & varX & "]

    """" & var1 & """ /r """ & var2 & """ """ & var3 & """"

  6. Test the expression
        
    Dim var1, var2, var3
    var1 = "dynamic string one"
    var2 = "dynamic string two"
    var3 = "dynamic string three"
     
    MsgBox """" & var1 & """ /r """ & var2 & """ """ & var3 & """"

Comments