How to check if a string contains "
I'm writing a little function to interact with a user inputting length in a form like 1'-11" Or something similar. I need to verify that both ' and " are used. However... I can't figure out how to get vb.net to recognize that I want to check if " is used and not use " to bracket a string.
Code:
For i = 0 To sString.Count - 1
If Not sString(i) = "1" Or "2" Or "3" Or "4" Or "5" Or "6" Or "7" Or "8" Or "9" Or "0" Or "." Or "-" Or "'" Or "" Then
'String is incorrect format, show msgbox error
End If
Next
I need to add Or """ :ehh:
Any thoughts?
Re: How to check if a string contains "
For a " you use "".
If TheString.Contains("""") Then
Or if you need to do it your way:
If Not sString(i) = """" Then
Re: How to check if a string contains "
Re: How to check if a string contains "
Could you also use chr(34) & chr(34)
THat's the character code for a "
Re: How to check if a string contains "
If you want to display double quotes in string literals then use a second double quote to escape it, e.g.
vb.net Code:
Dim str As String = "He said ""Hello"""
If you want to refer to the double quote character specifically then use ControlChars.Quote, e.g.
vb.net Code:
For Each ch As Char In sString
If Not Char.IsDigit(ch) AndAlso ch <> ControlChars.Quote Then
'String is not in correct format.
Exit For
End If
Next
There's never a reason to use Chr(34) in VB.NET as was done in VB6.