在文本框中查找单词 [英] Find a word in textbox

查看:84
本文介绍了在文本框中查找单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我想在文本框中找到一个词

我想知道单词是否在两个<>之间.然后,结果显示在列表框中

谢谢

OP的其他信息从下面的非解决方案中移出
打扰一下,我正在使用vb.net
请帮助我,非常有必要

Hello .

i want to find a word in the textbox

i want if the word was between two <> then , the result are displayed in a listbox

Thanks

OP''s additional information moved from non-solution below
Excuse me, i am work with vb.net
please help me , very necessary

推荐答案

您好,

如果您想修剪多个单词,这可以帮助您入门.

希望这会给您一些开始.

用VB更新


Hi there,

This is something to get you started on if you wanted to trim out multiple words.

Hopefully this will give you something to start with.

UPDATED WITH VB


''' <summary>
 ''' Gets the list items.
 ''' </summary>
 ''' <param name="p_textToSearch">The text to search.</param>
 Public Sub GetListItems(ByVal p_textToSearch As String)
     'listBox1 is the listbox you want to populate
     Dim items As New ListBox.ObjectCollection(listBox1)
     If (p_textToSearch.Contains("<")) AndAlso (p_textToSearch.Contains(">")) Then
         Dim wordsStrings As String() = p_textToSearch.Split(">"c)
         For Each wordsString As String In wordsStrings
             Dim firstIndexOfBracket As Integer = wordsString.IndexOf("<", StringComparison.Ordinal)

             If firstIndexOfBracket < 0 Then
                 firstIndexOfBracket = 0
             End If
             Dim preTrim As String = wordsString.Substring(firstIndexOfBracket)
             Dim altered As String = preTrim.Replace("<", "")

             items.Add(altered.Trim())
         Next

     End If
     listBox1.Refresh()
 End Sub











/// <summary>
/// Gets the list items.
/// </summary>
/// <param name="p_textToSearch">The text to search.</param>
public void GetListItems(string p_textToSearch)
{
    //listBox1 is the listbox you want to populate
    ListBox.ObjectCollection items = new ListBox.ObjectCollection(listBox1);
    if ((p_textToSearch.Contains("<")) && (p_textToSearch.Contains(">")))
    {
        string[] wordsStrings = p_textToSearch.Split('>');
        foreach (var wordsString in wordsStrings)
        {
            int firstIndexOfBracket = wordsString.IndexOf("<", StringComparison.Ordinal);

            if (firstIndexOfBracket < 0)
            {
             firstIndexOfBracket = 0;
            }
            string preTrim = wordsString.Substring(firstIndexOfBracket);
            string altered = preTrim.Replace("<", "");

            items.Add(altered.Trim());
        }
    }
    listBox1.Refresh();
}


这篇关于在文本框中查找单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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