0

Hey everyone. In stumped. How would you take a string and verfiy it is a word?

Example:

String a = sldkjf
String b = dog

The results should be, "dog" is a word and "sldkjf" is not.

Any direction would be greatly appreciated.

4
Contributors
7
Replies
37
Views
3 Years
Discussion Span
Last Post by RichardGalaviz
0

Question 1: How do you know "dog" is a word?

Question 2: If you didn't know if "dog" was a word or not, how would you find out?

Edited by cgeier

1

you could get a text file with a lot of words in it and then check for a specific word

System.IO.StreamReader reader = new System.IO.StreamReader("FILEPATH");
String text = reader.ReadToEnd();
if (System.Text.RegularExpressions.Regex.IsMatch(text, textBox1.Text))
    {
        BLABLA
    }
    else
        BLABLA
Votes + Comments
Helpful first post.
0

"Question 2: If you didn't know if "dog" was a word or not, how would you find out?"

I would look it up in a dictionary. Is there a C# class like a dictionary? Or is there another way I am missing?

0

Yes. You need to have an "electronic" version of a dictionary that contains valid words. This electronic version can be a text file. Additionally, new words are added to dictionaries from time to time, so you may need to update your file from time to time.

0

Do you want to write this with nested loops, or will a canned solution using regular expressions do?

Here's the regex version:
// At the top of your source:
using System.Text.RegularExpressions;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.