Click here to Skip to main content
15,943,103 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
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
Posted
Updated 12-Nov-12 4:27am
v2
Comments
Richard C Bishop 12-Nov-12 9:42am    
What language? What have you tried?

1 solution

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


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





C#
/// <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();
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900