您好我开发一个文字游戏,我要检查用户输入的有效字或不 请建议的方式,我可以检查机器人给定的字符串。
Hello I am developing a word game where i want to check the user input as valid word or not please suggest the way i can check the given string in android.
例如。字符串s =asfdaf 我想检查是否其一个有效的。
Eg . String s = "asfdaf" i want to check whether its a valid one.
有许多可能的解决方案,这一部分主要有以下
There are many possible solutions to this some are the following
使用网络词典的API
Use a web Dictionary API
http://developer.dictionary.com/
的http://googlesystem.blogspot.com/2009/12/on-googles-unofficial-dictionary-api.html
http://www.dictionaryapi.com/
如果你将preFER局部解
if you would prefer a local solution
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class WordChecker {
public static boolean check_for_word(String word) {
// System.out.println(word);
try {
BufferedReader in = new BufferedReader(new FileReader(
"/usr/share/dict/american-english"));
String str;
while ((str = in.readLine()) != null) {
if (str.indexOf(word) != -1) {
return true;
}
}
in.close();
} catch (IOException e) {
}
return false;
}
public static void main(String[] args) {
System.out.println(check_for_word("hello"));
}
}
本使用在所有Linux系统中的本地词表来检查单词
this uses the local word list found on all Linux systems to check for the word