您的位置:程序门 -> .net技术 -> vb.net



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


大家来讨论~~~~~~~这难道是.net中instr()的bug?[已结贴,结贴人:vanxining]
发表于:2007-08-01 19:10:18 楼主


下面是一个控制台程序的代码:
目的:得到“推荐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几个小技巧   -   软件技”!

奇怪!为什么?各位高手请指教!简直莫名其妙!
发表于:2007-08-01 19:29:001楼 得分:20
title   =   mid(html,   begin   +   7,   (last   -   (begin   +   7)   -   3))

mid函数的第3个值表示要返回的字符个数,而不是字符串的位置
发表于:2007-08-01 20:35:212楼 得分:0
原来如此……汗!非常感谢!


快速检索

最新资讯
热门点击