Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:stringliterals [2015/09/14] (current)
Line 1: Line 1:
 +====== VBScript String Literals ======
 +> **Developer:​** [[developer:​rhinoscript|RhinoScript]]
 +> **Summary:​** //How to use string literals in VBScript.//
 +
 +=====Overview=====
 +In VBScript, you enclose strings with double quote characters, and you use the ampersand (&) operator to concatenate strings. For example:
 +
 +<code vb>
 + Dim s
 + s = "​Hello"​
 + s = "​Hello"​ & " Rhino!"​
 +</​code>​
 +
 +What if you want to assign "Hello Rhino!"​ (including the quotes) to the variables? In VBScript, you can use two double quote characters to include a double quote character in the string. For example:
 +
 +<code vb>
 + Dim s
 + s = "Hello Rhino!"​
 +</​code>​
 +
 +Alternatively you can use the Chr(34) construct:
 +
 +<code vb>
 + Dim s
 + s = Chr(34) & "Hello Rhino" & Chr(34)
 +</​code>​
 +
 +Or, to make your code more readable, you can write a function.
 +
 +<code vb>
 + ​Function Quote(ByVal s)
 +   Quote = Null
 +   If (VarType(s) = vbString) Then
 +     Quote = Chr(34) & CStr(s) & Chr(34)
 +   End If
 + End Function
 +
 + '​...
 +
 + Dim s
 + s = Quote("​Hello Rhino!"​)
 +</​code>​
 +
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/stringliterals.txt ยท Last modified: 2015/09/14 (external edit)