新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

英文拼写检查java代码 英文拼写检查java代码

用java写的拼写检查功能

EditPlus 2.0 或3.30

我们提供的服务有:成都网站建设、成都做网站、微信公众号开发、网站优化、网站认证、肃南裕固族自治ssl等。为上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的肃南裕固族自治网站制作公司

在哪里都有下的。我一直都用这个,比记事本强多了

它对很多的语言的特殊字都标有颜色!

java实现按词头、词尾提取英文文档中的单词的完整代码代码

public class Test {

public static void main(String[] args) {

Test t =new Test();

File file = new File("E:\\桌面\\words.txt");

try {

ListString list= t.getWords(file, true,"h");

for (String string : list) {

System.out.print(string+"   ");

}

} catch (Exception e) {

e.printStackTrace();

}

}

/**

 * java实现按词头、词尾提取英文文档中的单词

 * @param file 原文件

 * @param isHead 按词头true 按词尾false

 * @param fix 关键词

 * @return

 * @throws Exception 

 */

public ListString getWords(File file , boolean isHead,String fix) throws Exception{

//读取文件中的内容到字符串str

FileInputStream fis = new FileInputStream(file);

BufferedInputStream bis = new BufferedInputStream(fis);

int i=0;

String str = "";

while ((i=bis.read())!=-1) {

str+=(char)i;

}

System.out.println(str);

bis.close();

fis.close();

//将str分割为单词数组

String[] words = str.split(" ");

ListString list = new ArrayListString();

if (isHead) {

for (String word : words) {

if (word.startsWith(fix)) {

list.add(word);

}

}

}else {

for (String word : words) {

if (word.endsWith(fix)) {

list.add(word);

}

}

}

return list;

}

}

如何判断一个字符串是java代码还是英文单词

Java中判断字符串的编码有两种思路:

一种是根据byte的长度判断,英文的字母数字好标点符号都是一个byte,且值在0-255之间

另一种是根据中文的Unicode取值范围判断,这个就是把所以的范围都包含,才能判断正确,参考unicode中文范围:

示例代码:

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class StringTest {

//英文占1byte,非英文(可认为是中文)占2byte,根据这个特性来判断字符

public static boolean checkChar(char ch) {

if ((ch + "").getBytes().length == 1) {

return true;//英文

} else {

return false;//中文

}

}

public static String checkString(String str) {

String res = "";

if (str != null) {

for (int i = 0; i str.length(); i++) {

//只要字符串中有中文则为中文

if (!checkChar(str.charAt(i))) {

res = "中文";

break;

} else {

res = "英文";

}

}

}

return res;

}

//判断是不是中文

public static boolean isChinese(char c) {

Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);

if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS

|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS

|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A

|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION

|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION

|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {

return true;

}

return false;

}

//判断是不是英文字母

public static boolean isEnglish(String charaString) {

return charaString.matches("^[a-zA-Z]*");

}

//根据中文unicode范围判断u4e00 ~ u9fa5不全

public static String isChinese(String str) {

String regEx1 = "[\\u4e00-\\u9fa5]+";

String regEx2 = "[\\uFF00-\\uFFEF]+";

String regEx3 = "[\\u2E80-\\u2EFF]+";

String regEx4 = "[\\u3000-\\u303F]+";

String regEx5 = "[\\u31C0-\\u31EF]+";

Pattern p1 = Pattern.compile(regEx1);

Pattern p2 = Pattern.compile(regEx2);

Pattern p3 = Pattern.compile(regEx3);

Pattern p4 = Pattern.compile(regEx4);

Pattern p5 = Pattern.compile(regEx5);

Matcher m1 = p1.matcher(str);

Matcher m2 = p2.matcher(str);

Matcher m3 = p3.matcher(str);

Matcher m4 = p4.matcher(str);

Matcher m5 = p5.matcher(str);

if (m1.find() || m2.find() || m3.find() || m4.find() || m5.find())

return "中文";

else

return "英文";

}

public static void main(String[] args) {

System.out.println("使用长度判断:");

System.out.println(checkString("Hello++"));

System.out.println(checkString("Hello++。、,?"));

System.out.println(checkString("Hello++编程"));

System.out.println(checkString("编程"));

System.out.println("\r\n使用正则表达式判断:");

System.out.println(isChinese("Hello++"));

System.out.println(isChinese("Hello++。、,?"));

System.out.println(isChinese("Hello++编程"));

System.out.println(isChinese("编程"));

System.out.println("\r\n使用Character.UnicodeBlock");

System.out.println(isChinese('h')?"中文":"英文");

System.out.println(isChinese(',')?"中文":"英文");

System.out.println(isChinese('。')?"中文":"英文");

System.out.println(isChinese('编')?"中文":"英文");

}

}


网页题目:英文拼写检查java代码 英文拼写检查java代码
分享URL:http://www.wjwzjz.com/article/hgsico.html
在线咨询
服务热线
服务热线:028-86922220
TOP