Solved

Finding Location of Selected Text in an Array

Posted on 2006-07-13
4
162 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 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