By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

How to put this " symbol into a string?

P: n/a
hi all

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

cheers

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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))

"Roy T" <Ro**@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
hi all

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

cheers

Nov 21 '05 #2

P: n/a
Just put two " into the string: myString = "Hello ""World"""

would be: Hello "World"

"Roy T" <Ro**@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
hi all

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

cheers
Nov 21 '05 #3

P: n/a
Just escape it with another " char (two consequtive " chars)

"Roy T" <Ro**@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
hi all

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

cheers
Nov 21 '05 #4

P: n/a
* "=?Utf-8?B?Um95IFQ=?=" <Ro**@discussions.microsoft.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
* "=?Utf-8?B?Um95IFQ=?=" <Ro**@discussions.microsoft.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

P: n/a
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

P: n/a

"Cablewizard" <Ca*********@Yahoo.com> wrote in message
news:ug**************@TK2MSFTNGP12.phx.gbl...
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.
Nov 21 '05 #8

P: n/a
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" <Ca*********@Yahoo.com> wrote in message
news:ug**************@TK2MSFTNGP12.phx.gbl...
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
* "=?Utf-8?B?Um95IFQ=?=" <Ro**@discussions.microsoft.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.