Wednesday, March 28, 2012

String with double quotes

Hello Everyone,

I have a little problem. I have to insert a string into a column of a database object.

For exmaple my string is : Dim filename as string = "C:\Temp\Hello.txt".. but my problem is I have to insert into db "path="C:\Temp\Hello.text"".

I don't know how to include double quote in my string. Please help.

to add a quote character to a quoted string you need to escape the quote

in vb this is done by doubling up the quote

for example to get this string:

"this string contains one quote character -> " <- see"

you actually need to use:

"this string contains one quote character -> "" <- see"

"path=""C:\Temp\Hello.text"""


Hellombanavige,

Thanks for your reply.. Your answer solved half of my problem. Now suppose if i have to add a value in between those string. For example

From your example "this string contains one quote character -> "" . If i have a string variable say dim x as string = "Hello" and I have to add this in between the present string and get the double quotes. How do i do this. Thanks a lot.


any doublequote that needs to be treated as a literal character needs to be doubled up.

dim x as string = "Hello"

dim y as string = "Testing literal quote -> """ & x & """ <-another literal quote..."

y actually equals: Testing literal quote -> "Hello" <-another literal quote...


Thanks for your help...

0 comments:

Post a Comment