Using a quote as a literal

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

Guest

How can I use a quote as a literal so it does get confused as not a literal?

Thanks!

Bob
 
How can I use a quote as a literal so it does get confused as not a literal?

Thanks!

Bob

Quotes can be escaped by doubling.

Dim s as String = "<img src=""image1.jpg"">"
 
BobAchgill said:
How can I use a quote as a literal so it does get confused as not a
literal?

Thanks!

Bob

If you mean within a string, try something like this:

Label1.Text = "This displays a quotation mark = ""!"

The double quotes before the exclamation mark will display as a single
quote, part of the literal.
 
pvdg42 said:
If you mean within a string, try something like this:

Label1.Text = "This displays a quotation mark = ""!"

The double quotes before the exclamation mark will display as a single
quote, part of the literal.
True, but ersonally I prefer to use ControlChars.Quote and build the string
up as I find it easier to read

guy
 
So what would that look like in a literal string nested with variables? Like
this??

strMyString = "I am about to have a "COW" for the " + Counter + " time!"

strMyString = "I am about to have a ControlChars.Quote COW
ControlChars.Quote for the " + Counter + " time!"

Thanks! Bob
 
BobAchgill said:
So what would that look like in a literal string nested with variables? Like
this??

strMyString = "I am about to have a "COW" for the " + Counter + " time!"

strMyString = "I am about to have a ControlChars.Quote COW
ControlChars.Quote for the " + Counter + " time!"

Thanks! Bob

You have to put ControlChars.Quote outside of the string:

strMyString = "I am about to have a " & ControlChars.Quote & "COW" &
ControlChars.Quote & " for the " & Counter & " time!"

In my opinion, this is not easier to read than:

strMyString = "I am about to have a ""COW"" for the " & Counter & " time!"
 
You have to put ControlChars.Quote outside of the string:

strMyString = "I am about to have a " & ControlChars.Quote & "COW" &
ControlChars.Quote & " for the " & Counter & " time!"

In my opinion, this is not easier to read than:

strMyString = "I am about to have a ""COW"" for the " & Counter & " time!"

Not to mention the minor performance hit for string concatenation for
using ControlChars.Quote

Thanks,

Seth Rowe
 
rowe_newsgroups wrote:
Not to mention the minor performance hit for string concatenation for
using ControlChars.Quote

Surely the compiler evaluates such things at compile-time? Or is that where
you're saying the performance hit comes?


Ugh! I just put

Dim a As Integer = CInt(1 / Math.Sin(0))

and it didn't complain until run-time. So it has a limit to what it'll try
to evaluate, e.g. it does complain about

Dim a As Integer = CInt(1 / 0)

"Constant expression not representable in type Integer".

Andrew
 
Not to mention the minor performance hit for string concatenation for
using ControlChars.Quote

Thanks,

Seth Rowe

ControlChars.Quote is a constant so the compiler concatenates it a
compile time. Now the Counter variable, not being a constant, will
cause a concatenation at runtime, but there's not performance hit to
using ControlChars.Quote. I agree with Goran that using "" is easier
to read.

Chris
 
ControlChars.Quote is a constant so the compiler concatenates it a
compile time. Now the Counter variable, not being a constant, will
cause a concatenation at runtime, but there's not performance hit to
using ControlChars.Quote. I agree with Goran that using "" is easier
to read.

Chris- Ocultar texto de la cita -

- Mostrar texto de la cita -

Hi Bob

You can use quotes in this way:

Dim strCad as String = "I am about to have a ""COW"" for the " +
Counter + " time!"

Just using double quotes... Do I make myself clear?
 
diAb0Lo said:
Dim strCad as String = "I am about to have a ""COW"" for the " +
Counter + " time!"

Just using double quotes... Do I make myself clear?

Yes, but I suggest to use '&' for string concatenation instead of '+'.
 
Back
Top