Solved

non-dictionary string

Posted on 2014-10-21
7
192 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 32

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 32

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

13 Experts available now in Live!

Get 1:1 Help Now