''' <summary>
''' 指定した文字列を倍精度浮動小数点数に変換できるか調べます。
''' </summary>
''' <param name="s">文字列。</param>
''' <returns>s を倍精度浮動小数点数に変換できる場合は true。
''' それ以外は false。</returns>Public Shared Function TryParseToDouble(ByVal s As String) As Boolean
Try
Double.Parse(s)
Catch ex As StackOverflowException
Throw
Catch ex As OutOfMemoryException
Throw
Catch ex As System.Threading.ThreadAbortException
Throw
Catch
Return False
End Try
Return True
End Function
Dim str As String = "123.45"
'浮動小数点数か調べる If System.Text.RegularExpressions.Regex.IsMatch(str, "^[-+]?[0-9]*\.?[0-9]+$") Then
Console.WriteLine("{0}は浮動小数点数です。", str)
End If
'すべての文字が数字か調べる文字列Dim str As String = "12345"
Dim flag As Boolean = True
Dim c As Char
For Each c In str
'数字以外の文字が含まれているか調べるIf c < "0"c OrElse "9"c < c Then
flag = False
Exit For
End If
Next'結果を表示If flag Then
Console.WriteLine("すべて数字です。")
Else
Console.WriteLine("数字以外の文字が含まれています。")
End If