Quick question for everyone, How can you display double quotes (“) in UFT One (formerly QTP)?How can you display quot in QTP/UFT

Say you have a requirement where you need to display, “Quick Test Professional” (within quotes). Using simple msgbox function, can you achieve that?

I have two ways of getting this but will hold on my answer for a while. Let us see who is the first one to answer this question correctly. Please put your answer in comments below.

Solution:

Here are the two ways to display double quotes in QTP:

1. Using ASCII Character Codes:

Chr function in QTP (UFT) uses ASCII character values. The ASCII code for double quotes is 34. Hence – using & as the concatenation operator – for our example we will use

msgbox "Using ASCII Code - " & Chr(34) & "Quick Test Professional" & Chr(34)

The output would be: Using ASCII Code – “Quick Test Professional”
ascii-chr-double-quotes-qtp-uft

 

2. Escaping double quotes with a double quote.

Normally to display a string in QTP, you would use

msgbox "Quick Test Professional" 

whose output would be without-quotes-qtp-uft

but in this case our requirement is to display the double quotes as well. In any programming or scripting language when you want to use a reserved character as a literal character , you need to escape it. To display a double quote, you need to escape the inner double quotes. Normally in most of the languages, the escape character is backslash ( \ ). In VBScript, the escape character is a double quote ( ” ) itself.

Hence, for our example, we will use

msgbox "Escaping Double Quotes with Double Quotes - " & """Quick Test Professional"""

Let us understand the latter part of code above """Quick Test Professional""" 

The first and last quot marked in red are enclosing the complete string as you would normally do. The quotes marked in blue are serving as an escape character for the quotes that we want to display.

The output would be: Escaping Double Quotes with Double Quotes –  “Quick Test Professional”escaping-double-quotes-qtp-uft

Here is the complete list of ASCII values that you can use for Chr() function in QTP/UFT. Dec and Char columns below are of our interest. Ascii Values for Chr function in QTP (UFT)

Please do comment below if this article has helped you.