Solved

Finding Location of Selected Text in an Array

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Any reason why this might be bad? 7 41
comparing string in C# 3 34
c# code 19 61
Events in static methods 3 31
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now