VB 2008中使用代码向文本框添加多个单词? [英] vb 2008 add more than one word to textbox using code?

查看:88
本文介绍了VB 2008中使用代码向文本框添加多个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个软件,用户在其中将网址输入文本框并单击一个按钮,以查看该站点的html编码中是否存在"word1".
如果用户输入"www.website.com",则vb将获取该站点的html代码并搜索html代码中是否存在word1.

我有下面的代码可以搜索"word1":

Hi,

I have a software where the user enters a web address into a textbox and clicks a button to see if there is ''word1'' in the html coding of that site.
If a user enters ''www.website.com'' then vb will grab the html code of that site and search whether word1 exists in the html code.

I have the code below which searches for ''word1'':

Dim c As Integer

        TextBox1.Text = source
        TextBox2.Text = "word1"

        c = SourceC.Text.IndexOf(TextBox2.Text)
        If c > 0 Then
            form2.Show()
        Else
            form3.Show()
        End If



源"是我为用户正在搜索的网站的html代码指定的名称,该名称被复制到TextBox1.

此代码还搜索临时存储在TextBox2中的"word1",它以我想要的方式工作,但是如何添加更多单词并要求vb检查TextBox1中是否存在word1或word2?

在此先感谢



''Source'' is the name I have given to the html code of the website being searched by the user which gets copied to TextBox1.

This code also searches for ''word1'' which is temporarily stored in TextBox2 and it works the way I want but how do I add more words and ask vb to check if either word1 or word2 exhist in TextBox1?

thanks in advance

推荐答案

使用字符串的split方法根据已建立的分隔符将字符串拆分为单词(空格可以),然后可以使用foreach遍历单词,然后使用布尔值告诉您是否找到了任何单词.另外,您可以使用Contains方法而不是IndexOf.该代码无论如何都无法正常工作,您将索引放在其中的变量应该是c,而不是r.拥有诸如TextBox1和c之类的毫无价值的变量名,会使您的代码难以阅读,并允许此类错误蔓延.
Use the string''s split method to split your string into words based on an established delimiter ( space is fine ), then you can use foreach to iterate over the words, and use a bool to tell you if any were found. Also, you can use the Contains method, instead of IndexOf. This code won''t work anyhow, the variable you put the index in should be c, not r. Having worthless variable names like TextBox1 and c makes your code hard to read and allows these sort of errors to creep in.


这篇关于VB 2008中使用代码向文本框添加多个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆