Solved

non-dictionary string

Posted on 2014-10-21
7
196 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 78

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now