-
May 25th, 2016, 10:15 AM
#1
Thread Starter
Lively Member
Searching longer keywords first then eventually the shorter once
I am attempting to find a way to search for long keyword tails first before searching for the shorter once in VB.NET. My research on Google never offered a way to search for words like that. This is for my grammar checker database that has numerous amounts of words that should do the replacements in a sequence. If you were to change the shorter once first, then one would not find a way of eliminating the errors that are left by the shorter once.... The shorter once are mainly meant for enhancing the grammar. I have just found a way of eliminating the stackoverflow on my code so that will not be an issue. I only mention this because there are those who are familiar with my code! If one were to offer a solution, would it work on a context menu? I am only mentioning this because, this is the only part that needs restructuring.
Code:
checkWord = replacements.Keys.ElementAt(nextCheckIndex)
foundIndex = RichTextBox1.Find(checkWord, startZ, RichTextBox1.TextLength, RichTextBoxFinds.WholeWord)
Last edited by nqioweryuadfge; May 25th, 2016 at 10:18 AM.
Reason: Grammar
-
May 26th, 2016, 11:30 AM
#2
Re: Searching longer keywords first then eventually the shorter once
What is replacements? Assuming it's a Dictionary of some kind:
Code:
Dim replacements As New Dictionary(Of String, String)
replacements.Add("aaa", "")
replacements.Add("aaaaa", "")
replacements.Add("a", "")
replacements.Add("aaaa", "")
replacements.Add("aa", "")
Dim orderedList As List(Of String) = replacements.Keys.Cast(Of String).OrderByDescending(Function(s) s.Length).ToList
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 28th, 2016, 07:53 AM
#3
Thread Starter
Lively Member
Re: Searching longer keywords first then eventually the shorter once
Originally Posted by .paul.
What is replacements? Assuming it's a Dictionary of some kind:
Code:
Dim replacements As New Dictionary(Of String, String)
replacements.Add("aaa", "")
replacements.Add("aaaaa", "")
replacements.Add("a", "")
replacements.Add("aaaa", "")
replacements.Add("aa", "")
Dim orderedList As List(Of String) = replacements.Keys.Cast(Of String).OrderByDescending(Function(s) s.Length).ToList
Hi, thanks for your help and reply!
What if its a dictionary of:
Private replacements As New Dictionary(Of String, List(Of String)). How would I implement that to allow me to search Long strings first, then eventually the shorter ones?
-
May 28th, 2016, 08:03 AM
#4
Thread Starter
Lively Member
Re: Searching longer keywords first then eventually the shorter once
Replacements is a dictionary of (Of String, List(Of String))
-
May 28th, 2016, 08:05 AM
#5
Thread Starter
Lively Member
Re: Searching longer keywords first then eventually the shorter once
How would one implement it in a RichTextBox search like this one:
Code:
checkWord = replacements.Keys.ElementAt(nextCheckIndex)
foundIndex = RichTextBox1.Find(checkWord, startZ, RichTextBox1.TextLength, RichTextBoxFinds.WholeWord)
-
May 30th, 2016, 02:39 AM
#6
Thread Starter
Lively Member
Re: Searching longer keywords first then eventually the shorter once
I tested your code is very slow! Plus, my dictionary is sorted so there is no need to sort it again! Anyway to make it work in my scenario?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|