如何检查给定字符串是否是一个字 [英] How to check whether given string is a word

查看:161
本文介绍了如何检查给定字符串是否是一个字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我开发一个文字游戏,我要检查用户输入的有效字或不 请建议的方式,我可以检查机器人给定的字符串。

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

这篇关于如何检查给定字符串是否是一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆