Solved

Finding Location of Selected Text in an Array

Posted on 2006-07-13
4
164 Views
Last Modified: 2011-10-03
So I have a RichTextBox, and an ArrayList containing the tokenized contents of that RichTextBox.  I can get the start location of my selection and length and all that good stuff.  Any time the RichTextBox contents change, I regenerate my ArrayList.

Now, basically, my quandry ends up being what is the best way to find a selected bit of text (a word, hopefully) within the array?  I need to take into account the fact that selected text can be in the array and textbox multiple times.

To describe further...take this text and pretend it is in a RichTextBox.  I highlight the second instance of RichTextBox expecting my function to return an int 15 (disregarding spaces and punctuation).

Thanks.
0
Comment
Question by:kansieo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17102258
Hash tables are great for looking up things quickly, versus an array or an ArrayList.  You could add a DictionaryEntry to a hash table that has the word, and the index:

Hashtable words = new Hashtable();

words.Add("Bob", new DictionaryEntry("Bob", 45));

Then, check quickly:

  if (words.Contains("Bob"))
  {
     DictionaryEntry find = (DictionaryEntry) words["Bob"];
  }

Bob
0
 

Author Comment

by:kansieo
ID: 17102477
I do need to output from the ArrayList/Hashtable in the order that it was put in...based on my (albiet limited) knowlege of Hashtables, it probably isn't possible to reconstitute the exact text that went into it--right?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 200 total points
ID: 17103566
What version of .NET do you have?  2002, 2003, or 2005?  I am hoping for 2005, where you can use the OrderedDictionary to get what you need.

Bob
0
 

Author Comment

by:kansieo
ID: 17105571
SharpDevelop on top of .NET Framework 2.0...looks like I can use it, and it looks like a great compromise.

Thanks a million!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question