Solved

non-dictionary string

Posted on 2014-10-21
7
205 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 82

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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

635 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