Quick question for everyone, How can you display double quotes (“) in UFT One (formerly QTP)?
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”
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
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”
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.
Please do comment below if this article has helped you.
Hi ankur,
please tell me how can i capture the text from the msgbox.
i hope i ll get answer soon from you…..
hi ankur
i am vijaya and i am new to this blog.i have a doubt in qtp,can u plz help me
i wrote a program to display runtime data displayed in msgbox.how can i copy data displayed to msgbox to notepad?
Hi Name,
I am Rajesh from SiliconIndia. I am also an avid blogger for a while now and participating actively in Indian blogosphere. I read your blog posting and found them very interesting and informative. We would love to see a copy of your blogs posted here, whenever you are posting it on blogger.com. Here are some of the benefits of posting your blogs here:
We have a strong community of 500,000 Indian professionals
Best blogs of 2008 to be published in a book “SiliconIndia bLoG PrinT”
Best blog to be printed in SliconIndia & SmartTechie magazines each month
Chance to be featured on homepage everyday
We appreciate your community initiative here and in helping build a more powerful India! Also, if you have any ideas or want to volunteer to help for SiliconIndia, we would be more than excited to get your help.
Rajesh
rajesh@siliconindia.com
98867 34775
MsgBox “””QTP – QuickTest Professional”””
MsgBox “””QTP – QuickTest Professional”””
The answer for the double quote question is
msgbox (chr(34)+”Quick TestProfessional”+chr(34))
From the solution of the above posts I noticed that you also get “1#” displayed in the message box. I just tried excluding the “1#” just so that “Quick Test Pro” is displayed with no extra characters. So, the result is
Msgbox “””Quick Test Professional””” ‘three quotes.
This is not a new solution but I thought I would share what I noticed.
Can use
Msgbox “”””
Regards and Thanks,
Niki
We can display Double Quotes (“) by following escape sequence method.
To Display Double Quotes (“) the Code will be:
Msgbox “”””
Regards and Thanks,
Niki well known Tiru
@ Maniz and Yaniv: Nice but there is one more method…can you think of that?
MsgBox “#2: ” & Chr(34) & “QTP – QuickTest Professional” & Chr(34)
we can use msgbox chr(34) “QTP” chr(34)
Thanks Motevich! Bingo.
Let us see if someone else can come up with an answer, without looking at the solution you posted.
This question was asked on the Testing Tools forums, I gave one answer there then thought I will put it as a question for wide range of audience on blog.
I found two answers too 🙂
Here you are, Ankur:
QTP quotes
Thank you for the great blog!