Solved

Finding Location of Selected Text in an Array

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Greetings C# program 17 107
Diagnostics with Net and Net.Sockets 2 28
Coding C# in Linux 8 69
Winform Module - What is the ASP.Net equiv 2 22
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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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