Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Finding Location of Selected Text in an Array

Posted on 2006-07-13
4
Medium Priority
?
168 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 800 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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.
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

604 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