Sign in to follow this  
Fixxer

C++: Search through a text box and find keywords

Recommended Posts

Fixxer    100
How would I go about searching through a text box for certain keywords. This more or less theory rather than asking for code, although if you have an example that would help too.

Share this post


Link to post
Share on other sites
njpaul    367
Well if you mean bring up a text box and use it to search for keywords throughout whatever is being displayed, this might help.

Last year one of our school projects was to display a TV guide to the user through a GUI (using QT). We had to load the data from files and stuff like that, and one of our things was to add filters and searches to the guide. What I did, and I assume most others did, was create a class to store programs in the guide. The program would have a text description that I could retrieve through member functions. When the user would type in a text string, I would loop through all the programs, grabbing their text, and search through it with the stl algorithms. If it found the text, it would mark the program as visible and move on to the next program. Then I would only display the programs marked visible. You could change the action to highlight the text, or jump to the text and wait for the user to hit a "find next" button.

Share this post


Link to post
Share on other sites
Fixxer    100
i mean something more like if i typed

#include

in DevC++.

How do they turn it blue? Thats what im shooting for.

At the end of the program loop it would search through the text box and if it found a keyword say I had listed in a text file or in the program or somewhere, it would turn that text blue.

Share this post


Link to post
Share on other sites
Motz    136
Most toolkits provide a method to search for a pattern (string) in a textbox and find what offset it occurs at. Use this method to loop through each occurrence of the pattern and then apply a "tag" (or whatever your toolkit supplies) to that substring which gives it the desired properties (e.g. Different Font, Larger Point Size, Different Colour).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this