【发布时间】:2016-04-13 19:20:17
【问题描述】:
我正在使用正则表达式从网站上抓取数字,然后我想将其乘以 4。
Dim thepage As String = postreqreader.ReadToEnd
Dim r As New System.Text.RegularExpressions.Regex("Views"">\(....)")
Dim matches As MatchCollection = r.Matches(thepage)
Dim kwota As String
For Each itemcode As Match In matches
kwota = itemcode.Groups(1).Value
Next
Dim stringToInteger As Integer = Convert.ToInt32(kwota)
之后出现错误:An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll。我不知道怎么做。我正在使用 Microsoft Visual Studio、VB .net。 kwota 变量包含 15.2 作为字符串。
【问题讨论】:
-
您正在创建一个 int (stringToInteger) 并将其分配给 textbox1.text(这是一个字符串)。
-
问题是,即使我删除分配给文本框也会显示错误
-
嗯,
15.2肯定不是int,而是double、float或decimal。 -
我改成了
Dim tehe As Double = Convert.ToDouble(text)并没有改变任何东西:/ -
您能否发布所有代码,包括您尝试抓取的网站,并为您检查代码。