Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I have a RichTextBox and a listbox. If a User Typed One string and hit space bar then again typed on string and if user hit alt+space(which is shortcut to display listview, to show filter data of second string). My Problem is, Ihave take the string after space and match that with my listbox and show suggesition to the user


i am using :
C#
SelectExactMatch(richTextBox1.Text);

C#
public void SelectExactMatch(string find)
        {
            listBox1.SelectedIndex = listBox1.FindString(find);
        }


this code to search string in listbox... but problem is richtextbox1.text means all the the text
i just want to take that string that user hit alt+space to the near one...



pls give me some suggestion or hint...
Posted
Updated 9-Jun-13 20:30pm
v3
Comments
Alexander Dymshyts 7-Jun-13 4:35am    
You can search for a space in richTextBox1.Text, and then you can save to another string rest of the input string
Anjanee Kumar Singh 7-Jun-13 4:40am    
so from your point of view what should i pass in my method
Alexander Dymshyts 7-Jun-13 5:46am    
I think you can pass a text of the richbox, then find space that you need, and create a new string with a text that you need and you will get something like listbox1.SelectedIndex = listbox1.FindString(newFindString);
Or you can wait for alt+space event is raised, and when it raised you can save what you need in some property

1 solution

You can use Split() method.

Have a look at the following link[^].

An example from the link;

C#
string s = "there is a cat";
//
// Split string on spaces.
// ... This will separate all the words.
//
string[] words = s.Split(' ');
foreach (string word in words)
{
    Console.WriteLine(word);
}


so in this case second word which is "is"=> you can find it in words[1]

Adaptation to your code:
SelectExactMatch(words[1]);

Good luck,
OI
 
Share this answer
 
Comments
Anjanee Kumar Singh 7-Jun-13 4:33am    
Orcun Sir will it check all the space from start to end
Orcun Iyigun 7-Jun-13 6:25am    
Have you tried what I have suggested? Debug it and you will understand.
Anjanee Kumar Singh 7-Jun-13 4:48am    
This code is collecting all the string .. but i need to check space before that word for which user pressed alt+space.

ex:

This Is My Ho(only before Ho i want to check space and give some suggestion related to Ho)..Thank You
Orcun Iyigun 7-Jun-13 6:24am    
So instead of words[1] you just give words[words.count-1]. which is Ho.

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