How to put this " symbol into a string?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all

i would like to include the double quote " symbol into the string. How can
i do it?

cheers
 
There are a lot of ways of doing so... But I personally prefer the
following:

Dim strMyString as string = "ABCDEFG~HIJK"
strMyString.Replace("~", chr(34))
 
Just put two " into the string: myString = "Hello ""World"""

would be: Hello "World"



hi all

i would like to include the double quote " symbol into the string. How can
i do it?

cheers
 
Just escape it with another " char (two consequtive " chars)

hi all

i would like to include the double quote " symbol into the string. How can
i do it?

cheers
 
* "=?Utf-8?B?Um95IFQ=?= said:
i would like to include the double quote " symbol into the string. How can
i do it?

\\\
Dim s As String = _
"He said: ""Hello World!"""
Dim t As String = _
"He said: " & ControlChars.Quote & "Hello World!" & ControlChars.Quote
///

Notice that there is no performance loss in using the string
concatenation operator in the 2nd sample, the string is concatenated by
the compiler and stored as a single constant in the assembly.
 
FYI, the ControlChars.Quote method is my favorite.
It is very clear what you are doing and makes code very readable and
maintainable.
Much more so than "" """", which can be confused with '', '''' (single quotes)
IMHO, I would recommend this as a "best practice".

Gerald
 
* "Cablewizard said:
FYI, the ControlChars.Quote method is my favorite.
It is very clear what you are doing and makes code very readable and
maintainable.
Much more so than "" """", which can be confused with '', '''' (single quotes)
IMHO, I would recommend this as a "best practice".

I always use the double quotes inside the string literal. It's IMO just
a matter of personal preference.
 
FYI, the ControlChars.Quote method is my favorite.
It is very clear what you are doing and makes code very readable and
maintainable.
Much more so than "" """", which can be confused with '', '''' (single quotes)
IMHO, I would recommend this as a "best practice".

I wouldn't. I find the string concatenation much harder to read.
 
I suppose it is personal preference.
Personally, I like to see the quotes stand out as in the concatenation.
Really helps me visualize exactly what is going on, especially when constructing
SQL statements.
Either way works just great.

Gerald

Cablewizard said:
FYI, the ControlChars.Quote method is my favorite.
It is very clear what you are doing and makes code very readable and
maintainable.
Much more so than "" """", which can be confused with '', '''' (single quotes)
IMHO, I would recommend this as a "best practice".

Gerald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top