Page 1 of 1

Text search in Webview Control

Posted: Monday 17th May 2021 4:48am
by Quincunxian
I have a webview that I load with text that I wish to search.
There are two issues.

Search Text List
Apple
Banana
Pineapple

If the web view text is:
Apple
Pineapple
Pineapple
Apple
Banana

In this example, the the word Pineapple is never found.
The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again.
So once it finds the second instance of the word 'Apple', it does not go back and search at the beginning for for any other words.
In the WebView.FindText(SearchWord,Backward,CaseSensitive,Wrap), If you set the parameter 'warp' to true, it goes into an unending loop.

The second, issue is that there is no way to search for a 'whole word'.
If 'vacant' is part of the searched text and you search for 'can' , it counts as one, the instance inside the other word.
You can search for 'can ' with the added space but in a replace function, it will replace the space as well.

I'm using a webview instead of a TextEditor, as I can't get it to highlight multiple instances in different colours which is the requirement.

Any ideas ?

Re: Text search in Webview Control

Posted: Monday 17th May 2021 6:49am
by stevedee
Quincunxian wrote:
Monday 17th May 2021 4:48am
...The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again...
My only idea is that you try to reload the page before a search to force it to start at the beginning
...The second, issue is that there is no way to search for a 'whole word'...
Try putting the word in double quotes, so "back" will not find the word background

Re: Text search in Webview Control

Posted: Monday 17th May 2021 8:22am
by BruceSteers
Quincunxian wrote:
Monday 17th May 2021 4:48am
I have a webview that I load with text that I wish to search.
There are two issues.

Search Text List
Apple
Banana
Pineapple

If the web view text is:
Apple
Pineapple
Pineapple
Apple
Banana

In this example, the the word Pineapple is never found.
The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again.
So once it finds the second instance of the word 'Apple', it does not go back and search at the beginning for for any other words.
In the WebView.FindText(SearchWord,Backward,CaseSensitive,Wrap), If you set the parameter 'warp' to true, it goes into an unending loop.

The second, issue is that there is no way to search for a 'whole word'.
If 'vacant' is part of the searched text and you search for 'can' , it counts as one, the instance inside the other word.
You can search for 'can ' with the added space but in a replace function, it will replace the space as well.

I'm using a webview instead of a TextEditor, as I can't get it to highlight multiple instances in different colours which is the requirement.

Any ideas ?
I know not of webview but...
TextEditor will highlight search result. using HighlightString() command
Public Sub HighlightString(Text As String, Optional IgnoreCase As Boolean, Optional WordOnly As Boolean)

color can be set setting TextEditor1.Styles[Highlight.Highlight].Color

Re: Text search in Webview Control

Posted: Monday 17th May 2021 10:02pm
by Quincunxian
Thanks Bruce,
I did try the text editor earlier on but the requirement was to highlight multiple words in different colours.
I'm a (would be) author writing fantasy and I've created a program in Gambas to help me do that.

I wanted to scan a chapter of text, around 5000 words, and be able to hi-light a number of words by their type.
Each type has a colour. There are around 10 types.

The problem I had with the text editor is that I could do one colour but not preserve that and do another.
The Code editor in gambas is obviously capable of doing that but cannot find an example. No surprises there.
I played around with it for a number of days then gave up and got the limited success with the web view.

Thanks SteveDee:
I tried the "word" process but the search identifies it as a word with quotes.
So word is not found, but "word" is found.
I've tried WebView.Refresh and that didn't work and a reload of the page means that I have to save the existing hi-light then do the next word then save...
One process that looks for sets of words, as 2800+ in the database so this may not be workable on a process time basis.

Thanks Guys.
I'll go back and try out the text editor again to see I've missed something.