Reputation: 82
Here I want to Add double quotes ("
) in my sentence, but it insert Two (") at single place as shown in picture. Have tried Chr(34)
and Replace()
.
Please help me to insert double quotes in Dictionary Item using VBScript in UFT12.
I don't want to use Msgbox to display this String.
Dim Dict
Set Dict=CreatObject("Scripting.Dictionary")
Dic("Value")="I went to mall....Where I met my Friends "&Chr(32)&"XYZ" & "DEF"&Chr(34)&". We enjoied a lot."
When I "Watched" Dic("Value")
using UFT12.0 It gives shows :
"I went to mall....Where I met my Friends ""XYZ & DEF"". We enjoied a lot."
Upvotes: 0
Views: 688
Reputation: 30123
Here's an example, in addition to exhaustive Ekkehard.Horner's answer (returns the string and the position of the first occurrence of "
and doubled ""
in that string):
option explicit
Dim myString0, myString1, myString2, myString4
myString0 = "none double quotes"
myString1 = "with ""double"" quotes 1"
myString2 = "with " & Chr(34) & "double" & Chr(34) & " quotes 2"
myString4 = "twice """"double"""" quotes"
Wscript.Echo Wscript.ScriptName & ": Using Double Quotes" _
& vbNewLine & myString0 _
& vbTab & InStr( 1, myString0, Chr(34) , vbTextCompare) _
& vbTab & InStr( 1, myString0, Chr(34)&Chr(34), vbTextCompare) _
& vbNewLine & myString1 _
& vbTab & InStr( 1, myString1, Chr(34) , vbTextCompare) _
& vbTab & InStr( 1, myString2, Chr(34)&Chr(34), vbTextCompare) _
& vbNewLine & myString2 _
& vbTab & InStr( 1, myString2, Chr(34) , vbTextCompare) _
& vbTab & InStr( 1, myString2, Chr(34)&Chr(34), vbTextCompare) _
& vbNewLine & myString4 _
& vbTab & InStr( 1, myString4, Chr(34) , vbTextCompare) _
& vbTab & InStr( 1, myString4, Chr(34)&Chr(34), vbTextCompare)
Output:
==>cscript //nologo 28778280.vbs
28778280.vbs: Using Double Quotes
none double quotes 0 0
with "double" quotes 1 6 0
with "double" quotes 2 6 0
twice ""double"" quotes 7 7
Upvotes: 1
Reputation: 38755
Your debugger tool displays the value of a string variable as a literal (what you would have to type/paste into your editor). Evidence: the surrounding double quotes.
Your .. "&Chr(32)&"XYZ" & "DEF"&Chr(34)&". ..
proves: Using Chr() is inferior (extra function call and noise) and error prone (Chr(wrong number) to escaping " by "".
Upvotes: 1