Results 1 to 6 of 6

Thread: quotes within quotes

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    couldn't find this in the documentation anywhere (I hate MSDN):

    How do you escape quotes in a string? e.g. in other languages you can do "\"" or "'" or """" to end up with a single quote. How is this accomplished in VB? (I really don't want to use Char(), which is a serious pain in the rear)

    Thanks,
    --Josh

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    use Double Quotes, ie.
    John "Billy Bones" Smith is the man!
    would be
    Code:
    "John ""Billy Bones"" Smith is the Man!"
    Hope this helps
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You can use """ to do it,
    Code:
    MsgBox """
    unfortunatley you can't do it inside a long string something like this
    Code:
    MsgBox "Sam Say's " & """ & "Hello" & """
    doesn't work


    If you want to incorparate it into a long string the best thing to do is to use a constant put in a standeard module

    Code:
    Public Const Q As String = """
    and then you can do something like

    Code:
    MsgBox "Sam Say's " & Q & "Hello" & Q

  4. #4
    Guest
    I like to use the Chr$ function:


    Code:
    Private Sub Form_Load()
    MsgBox "Hello " & Chr$(34) & "Sam" & Chr$(34) & " if that is your real name ;)"
    End Sub
    [Edited by denniswrenn on 08-14-2000 at 10:02 PM]

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    hmmm well my problem is that I'm messing with lots of HTML, so there are a lot of quotes being bandied about. For instance:

    I've got to do a whole bunch of substitutions along the likes of:

    Code:
    Replace(IMWnds(i).nHTML, "<!--", "</FONT><FONT COLOR=""#000000"" SIZE=1>", 1, -1, vbTextCompare)
    Can I do it with double quotes like so?

    In perl I'd just do:

    Code:
    "</FONT><FONT COLOR=\"#000000\" SIZE=1>"
    PLEASE tell me I don't have to do:
    Code:
    Dim sReplace As String
    sReplace = "</FONT><FONT COLOR=" & Char(34) & "#000000" & Char(34) & "SIZE=1>"
    Replace(IMWnds(i).nHTML, "<!--", sReplace, 1, -1, vbTextCompare)
    I'm beginning to see why people shun VB in favor of more powerful/yntactically nicer languages...

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    answered my own question with a little testing:

    Code:
    IMWnds(i).nHTML = Replace(IMWnds(i).nHTML, "<!--", "</FONT><FONT COLOR=""#000000"" SIZE=1>", 1, -1, vbTextCompare)
    IMWnds(i).nHTML = Replace(IMWnds(i).nHTML, "-->", "", 1, -1, vbTextCompare)
    IMWnds(i).nHTML = Replace(IMWnds(i).nHTML, """>:</FONT>", """ SIZE=3>:</FONT>", 1, -1, vbTextCompare)
    IMWnds(i).nHTML = Replace(IMWnds(i).nHTML, "</BODY></HTML>", "", 1, -1, vbTextCompare)
    Not the most readable, but it works.


    Thanks,
    --Josh
    http://aimlog.sourceforge.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width