Solved

non-dictionary string

Posted on 2014-10-21
7
197 Views
Last Modified: 2014-11-18
Hi Dear,

Could you please help me how to check the string is dictionary word or non-dictionary word ?



thanks
0
Comment
Question by:mannevenu26
7 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 40394171
THE QUESTION IS NOT CLEAR

IF YOU HAVE A DATABASE AND WANT TO CHECK IF A WORD EXIST IN SOME TABLE YOU CAN DO A SELECT QUERY

AND SEARCH FOR IT
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40394187
Look at the following, they seem to be what you are asking for.
http://msdn.microsoft.com/en-us/library/bb347013%28v=vs.110%29.aspx
and
http://msdn.microsoft.com/en-us/library/kw5aaea4%28v=vs.110%29.aspx

You haven't specified if the string is a key or a value - dictionaries store two parts for each entry.


ps.
@king2002 - the question is about a dictionary, not a database.
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40394198
the way the question is worded it could also be a search to see if the word (string) exists in say the oxford dictionary as in the method to disallow dictionary words in a password
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 33

Expert Comment

by:sarabande
ID: 40394232
how to check the string is dictionary word or non-dictionary word ?
I would agree with the ContainsKey suggestion Andy Ainscow has posted.

if  (!myDict.ContainsKey(myString))
{
     // ...

Open in new window

what is the recommended solution if looking for string keys in a c# dictionary container.

if looking for "words" in a dictionary, you rarely will look for the value part but for keys only.

Sara
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40394525
@sara - You mean something like this:
using System;
using System.Collections.Generic;
using System.Linq;

static class DictionaryExample
{
	public static void Main()
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		dictionary.Add("Apple", "This is the definition of an apple.");
		dictionary.Add("Banana", "This is the definition of a banana.");
		dictionary.Add("Cherry", "This is the definition of a cherry.");
		dictionary.Add("Grape", "This is the definition of a grape.");
		dictionary.Add("Lemon", "This is the definition of a lemon.");
		dictionary.Add("Orange", "This is the definition of an orange.");
		dictionary.Add("Pear", "This is the definition of a pear.");
		string[] lookups = new string[] { "Apple", "Pear", "Banana" };
		var definitions = (from pair in dictionary 
					    from lookup in lookups
					    where pair.Key.Equals(lookup, StringComparison.InvariantCultureIgnoreCase)
					    select pair);

		foreach (var pair in definitions)
			Console.WriteLine(string.Format("{0} - {1}", pair.Key, pair.Value));
		Console.ReadLine();
	}
}

Open in new window

Produces the following output:Capture.JPG
-saige-
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40394627
This is a copy/paste of code from the links I posted initially:

// ContainsKey can be used to test keys before inserting  
// them. 
if (!openWith.ContainsKey("ht"))
{
    openWith.Add("ht", "hypertrm.exe");
    Console.WriteLine("Value added for key = \"ht\": {0}", 
        openWith["ht"]);
}


...


// When a program often has to try keys that turn out not to 
// be in the dictionary, TryGetValue can be a more efficient  
// way to retrieve values. 
string value = "";
if (openWith.TryGetValue("tif", out value))
{
    Console.WriteLine("For key = \"tif\", value = {0}.", value);
}
else
{
    Console.WriteLine("Key = \"tif\" is not found.");
}

Open in new window


which demonstrates both of the methods detailed in the two links.  Namely how to test if a string (key) is in a dictionary collection.
0
 
LVL 40
ID: 40395064
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

785 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