Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Location
    South Africa
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB.net escape character

    ASP and VB.net

    How would i put an inverted comma (") in a string? is there an escape character like in java? (\")

    Say i want to put the following in a string:
    "This is in inverted commas" and this isn't.

    Something like:
    Dim str as String = "\"This is in inverted commas\" and this isn't."

    ???
    Bypass your proxy and get anonymous internet surfing FREE!

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Double-double quotes

    strString="""This is in double quotes"" and this isn't"

    I think...

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ways

    Dim s As String = chr(34) + "your string"

    or

    Dim s As String = """your string"

    3 time " for the second version

    but you can do a function if you have often this problem

    Public Function myDoubleQ(ByVal myText As String) As String
    Return myText.Replace(Chr(34), Chr(34) + Chr(34))
    End Function

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ways

    Originally posted by angiras
    Dim s As String = chr(34) + "your string"

    or

    Dim s As String = """your string"

    3 time " for the second version

    but you can do a function if you have often this problem

    Public Function myDoubleQ(ByVal myText As String) As String
    Return myText.Replace(Chr(34), Chr(34) + Chr(34))
    End Function
    That's an awful practice, use what spudhead posted it's much simpler.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    many

    I use only one function and overloads fir all my replacements
    something like :

    public Module myReplace

    Public Enum types As Byte
    one
    two
    three
    End Enum

    Public Function [do](ByVal text As String, ByVal type As types) As String
    Select Case type
    Case types.one
    Return text.Replace(Chr(34), Chr(34) + Chr(34)) ' "
    Case types.two
    Return text.Replace(Chr(39), Chr(39) + Chr(39)) ' '
    Case types.three
    so on ...
    End Select

    End Function

    End Module

    ---------------------------------------------------------
    and you use it :


    Dim mytext As String = myReplace.do(mytext, types.one)

    just give to the enums explicit values to recognize them
    Last edited by angiras; 05-29-2003 at 06:41 AM.

  • #6
    Regular Coder
    Join Date
    Feb 2003
    Location
    South Africa
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx a ton everyone!!
    Bypass your proxy and get anonymous internet surfing FREE!


  •  

    Posting Permissions

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