Click here to Skip to main content
12,943,742 members (59,566 online)
Rate this:
 
Please Sign up or sign in to 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 12-Nov-12 3:18am
Updated 12-Nov-12 4:27am
Nelek120.7K
v2
Comments
richcb 12-Nov-12 9:42am
   
What language? What have you tried?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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();
   }
  Permalink  
v3

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,970
Maciej Los 2,348
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100