Solved

non-dictionary string

Posted on 2014-10-21
7
200 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
[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
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 81

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

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 34

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video teaches viewers about errors in exception handling.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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