How to Display an Apostrophe in VBScript

Visual Basic Scripts (VBScripts) provide a lightweight solutions for desktop or web applications. The code is similar to VB, but it has fewer options and less scalability than the full VB language. Apostrophes are used to denote string variables in database procedures. VBScript is used to "scrub" database data, which means it ensures apostrophes are used for string variables and not for literal text such as an apostrophe in a last name. To test the application, developers display a text string with an apostrophe to test the code.

Instructions

    • 1

      Create a string variable and assign it a value. In this example, a last name is defined that contains an apostrophe character. The code below shows you how to create a VBScript variable:

      Dim LastName As String
      LastName = "O'Brian"

    • 2

      Scrub the data for SQL. To indicate that a literal apostrophe is needed for SQL, insert two apostrophe characters into your string. The following code ensures your SQL string is formed properly:

      LastName.Replace(" ' ", " '' ")

      In this code, the first parameter in parenthesis finds an apostrophe in the last name and replaces it with two apostrophe characters.

    • 3

      Print the results to the screen. The following code writes the results to your screen:

      Response.Write(LastName)

      The scrubbed data displays the apostrophe twice. This ensures that the information sent to the database server is a properly formed string.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured