Jump to content

Double Quote as string

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
How can I store a double quote as a string in visual basic?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You need to escape it:

MyString = "\""
str1 = "President Lincoln said \"Four score and seven years ago...\""


#3
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Ok, Thanks alot. It were something I never thought about before and then when I now needed to use it, I just thought; How can this possible work?

Thanks again.

#4
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
The thing is, it didn't work.

#5
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Well I solved it myself:

Insetead of:

Dim MyString as string = ""

It was just to write:

Dim MyString as string = """"

And the string got the value "
A little bit strange perhaps.

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very odd indeed. I wouldn't expect repeating an escapable char twice would escape it, but then again, this is Visual Basic.. :)

#7
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
hehe :D I wrote the correct solution before, but didn't even test if it worked since it looked completely wrong (It was just two empty strings between each other).

Edited by Vswe, 04 May 2009 - 12:03 PM.
misspelled


#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts

Jordan said:

Very odd indeed. I wouldn't expect repeating an escapable char twice would escape it, but then again, this is Visual Basic.. :)

Yeah, that's how it's done in VB. Escape sequences don't work in VB. This problem comes up quite a lot in VBA in particular, where you are writing macros to concatenate data from various string fields.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Just another reason VB sucks, IMO.

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Hey, do you hear me disagreeing? :) But VB as a syntax is often the only option, thanks to Microsoft deciding to use it in all their office macros.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,248 posts
Well that's kinda annoying. Which is one of the reasons I don't like VB. :D

Why can't you use C# for office macros?

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Maybe you can - but of course, Microsoft use VBA (a derivative of VB) as the language that macros are recorded in.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums