• Advertisement
Sign in to follow this  

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

This topic is 4618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
I found a command in the N3D SDK that searches through the textbox =)

N3D is a great tool.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement