Click here to Skip to main content
11,703,631 members (68,153 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: find
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
Edited 12-Nov-12 4:27am
Nelek73.9K
v2
Comments
richcb at 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
0 Maciej Los 570
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 410
3 F-ES Sitecore 165
4 Andy Lanng 159
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2015
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