读书人

大家来讨论~这难道是.NET中Instr()的b

发布时间: 2012-02-06 15:52:45 作者: rapoo

大家来讨论~~~~~~~这难道是.NET中Instr()的bug?


下面是一个控制台程序的代码:
目的:得到“推荐Visual Basic几个小技巧 ”。

Module Module1

Sub Main()

Getit()
Console.ReadKey()


End Sub

Sub Getit()
html = " <title> 推荐Visual Basic几个小技巧 - 软件技术 - 编程魔方 - 电脑报 CPCW电脑社区 中国最大的电脑初学者社区 硬件软件网络数码游戏在线答疑 学电脑从这里开始 - powered by Discuz! Archiver </title> "
Dim Title As String
Dim Begin, Last As Integer
Begin = InStr(html, " <title> ")

Last = InStr(html, "软件技术 ")

Title = Mid(html, Begin + 7, Last - 5)
Console.WriteLine(Title)
End Sub


End Module

运行程序,你会发现结果是“推荐Visual Basic几个小技巧 - 软件技”!

奇怪!为什么?各位高手请指教!简直莫名其妙!

[解决办法]
Title = Mid(html, Begin + 7, (Last - (Begin + 7) - 3))

mid函数的第3个值表示要返回的字符个数,而不是字符串的位置

读书人网 >VB Dotnet

热点推荐