|
You're welcome
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi there
I have a file with allot of sentences. I need to make a dictionary with the words from that file. Until now I've separated the words and sort them using Split() and Sort() methods. My problem is to make a list without duplicate words. How can I do that?
static int n = 0;
public static string[] NoDuplicate(string[] array)
{
int i;
string[] res = (string[])array.Clone();
for (i = 0; i < array.Length-1; i++)
if (array[i + 1] != array[i])
res[n++] = (string)array[i];
return res;
}
1) how can I do it more neat?
2) i don't like that method because is initialized using Clone() and the lenght is too big.
many thx
|
|
|
|
|
Store words in dictionary. Before adding new word check if the dictionary already contains it or not.
|
|
|
|
|
First, I'd use a List instead of an array because a List can grow dynamically, and will only be as large as is required to store your data. To avoid duplicates, you could do this:
List<string> dictionary = new List<string>()
string sentence = GetNextSentence();
string[] words = sentence.ToLower().Split(' ');
for (int i = 0; i < words.Length; i++)
{
if (!dictionary.Contains(words[i])
{
dictionary.Add(words[i]);
}
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Instead of using a List and calling it a dictionary, use a real Dictionary .
The Dictionary.Contains method is a lot faster than the List.Contains method.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
why would you need key & value just to store a word though? I would've gone with John's suggestion myself.
|
|
|
|
|
The difference is the style of the storage object.
A list is just that, an unsorted sequential list of items. To do a Contains() operation on it, you have to iterate through the list and check every item.
On the other hand, a dictionary is a form of hash table, so a Contains() operation only has to hash the key and check if it already exists.
in .net 3.5 you could instead consider a HashSet<String> This is specifically optimised for sets containing no duplicates.
Simon
|
|
|
|
|
|
Ignore what I posted before, Simon's HashSet<string> is perfect, and it has the ToArray if you need it.
Leaned something new today
|
|
|
|
|
HashSet is only in .Net framework 3.5 and i;m using vs2005
But the advice is soo great, thx to all
|
|
|
|
|
Take a look at the HashSet<String>[^] class (.net 3.5 only). It provides an optimised hash collection and it doesn't allow duplicates, (it just ignores attempts to add duplicates), and you can call ToArray() when you are done with it if you really need a string array.
Simon
|
|
|
|
|
Nice find Simon, hadn't come accross this one before... always good to learn something new
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
How could we know if SQL Server express is installed with c#? Thanks
|
|
|
|
|
|
Wow thanks. I'll give it a try. I tried using registry before and it failed.
|
|
|
|
|
Why? If you need to connect to a database then try connecting to the database; if it succeeds, proceed; if it fails, tell the user.
I don't see how knowing whether or not the expected database engine is installed and running will help.
|
|
|
|
|
I've written a windows application that is periodically verifying the Inbox folder from Microsoft Outloox ( within an interval of 60 secounds ). This application is working and it does exactly what it has to do.
The problem is that the same code putted in a windows service ( the declaration and initialisation of the Outlook Objects are the same in both cases ) seems not to be working, because the Outlook Object is not initialising corectly.
At the time of initialisation only it throws and COM exception.
So..were i go wrong? I will apreciate any advice.
P.S. I've tried to put the collecting function in a Class Library (DLL),and it's still not working.
|
|
|
|
|
try this link
http://support.microsoft.com/kb/237913
hope this will help you
na
|
|
|
|
|
Hi,
I have developed an application that inserts lots of data from a spreadsheet to a database. I would like to create a report (in notepad or anything) that states how many records were successfully inserted, failed, etc.
Can anyone assist me accomplish this?
Regards
Mvelo Walaza
Developer
Telkom SA
modified on Monday, November 17, 2008 6:59 AM
|
|
|
|
|
can you please tell us which database you are using.
na
|
|
|
|
|
I am using Oracle.
Toad for Oracle Version 9.0.1
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
How can i connnect a home phone to a C#.net application sach that the application can answer the phone automatically and can send a call automatically
|
|
|
|
|
You're going to need cabling, and a whole hunka code.
|
|
|
|
|
Hi.
I need help with this thing.
I have a code in a form and the code has something like this:
CODE
CODE
CODE
SHOW some a new form and WAIT!! for the user to enter data
CONTINUE WITH THE CODE WHEN THE DATA IS ENTERED/SELECTED
CODE
CODE
CODE
..
..
Ok, i solved this with show dialog, but then the dialog gets full priority and the user CANT read and see data in the background-main form (it freezes or something).
How can this be solved with just Form.Show() and not with showdialog and the code after the request for show form to wait for data to be entered in the other form.
Thanks in advance.
Regards,
Matjaž
Força Barça!
|
|
|
|
|