|
-
Aug 30th, 2008, 06:34 PM
#1
Thread Starter
Member
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 """ 
Any thoughts?
-
Aug 30th, 2008, 06:42 PM
#2
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
-
Aug 30th, 2008, 07:02 PM
#3
Thread Starter
Member
Re: How to check if a string contains "
-
Aug 31st, 2008, 04:05 AM
#4
Lively Member
Re: How to check if a string contains "
Could you also use chr(34) & chr(34)
THat's the character code for a "
-
Aug 31st, 2008, 06:36 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|