locked
Escaping " in a string

    Question

  • How do I escape a " character in a string.

    I am used to "this is a \"string\" with 3 \" characters in it" but that doesn't seem to work and I cannot find any reference to doing this.

    VB.Net 2003

    Thanks

    Ken

    Tuesday, February 21, 2006 4:24 AM

Answers

  • if you just want to display a sting you can use

    string = "this is a " & chrw(34) & " String " & chrw(34) & " with 3 "  &chrw(34) & " characters in it"

    Andrew
    Tuesday, February 21, 2006 5:53 AM

All replies

  • escape?
    Tuesday, February 21, 2006 5:06 AM
  • The \ character in front of the " character, in some languages, is called an "escape" character telling the compiler/interpreter that an actual " character is required yet not baffling the syntax checker with too many "'s in and around the string.

    Tuesday, February 21, 2006 5:32 AM
  • if you just want to display a sting you can use

    string = "this is a " & chrw(34) & " String " & chrw(34) & " with 3 "  &chrw(34) & " characters in it"

    Andrew
    Tuesday, February 21, 2006 5:53 AM
  •  

    Right.....

    Thank you cake hole... I would have missed that because I think it's a C-land utilization.

    I think you have your answer....

    peace to you.

    Tuesday, February 21, 2006 6:04 AM
  • Thanks Andrew, that is exactly what I was after.

    Ken

    Tuesday, February 21, 2006 6:06 AM
  • You can also use double quotes:

    Module Module1

    Sub Main()

    Dim x As String = "this is a ""string"" with 3 "" characters in it"

    Console.WriteLine(x)

    End Sub

    End Module

    Tuesday, February 21, 2006 6:16 AM
    Moderator