david7777
05-28-2003, 12:52 PM
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."
??? :confused: :confused:
Spudhead
05-28-2003, 01:00 PM
Double-double quotes :)
strString="""This is in double quotes"" and this isn't"
I think...
angiras
05-28-2003, 06:54 PM
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
Roy Sinclair
05-29-2003, 01:35 AM
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.
angiras
05-29-2003, 06:28 AM
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
david7777
05-29-2003, 07:50 AM
Thanx a ton everyone!! :thumbsup: :D