如何在一篇含有字母和中文汉字的文章中读取中文,急急急!!!

如何在一篇含有字母和中文汉字的文章中读取中文,我想要将文件中的汉字全部取出来,怎么进行识别汉字和字母的区别,就是在的代码中提取出汉字描述等信息

Java,Js,Node都行

你也没说什么语言的。。正则表达式。

你可以先把整片文章读取出来,然后遍历每一个字,转换成字符类型,通过unicode看是字符还是文字,当然语言要支持unicode才行

首先识别文本的编码方式:
1 GBK(GB2312,GB18030) | UTF-16 | UTF-8 |UTF-32
2 分别叙述
2.1 如果是GBK方式,汉字由两个字节组成,每个字节>=128,英文字符 2.2 如果是UTF-16方式,都占两个字节,英文第一字符是ASCII 值,第二个是0,汉字每个字节>=128
2.3 如果是UTF-8 形式,汉字占3个字节,查看一下UTF-8的编码方式
3 编程实现
3.1 根据多个字符识别编码方式。
3.2 获取中文,根据中文的特征提取。
因本人资料不充足,无法给出程序。请参考
http://visionsky.blog.51cto.com/733317/895928/

只有英文字母和中文的话就比较好判断了~只要把文本拿过在进行遍历如果当前字符>=a并且<=z那么就舍弃,反之则保留~最终的到的就是全部的中文字符

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.IOException;
import java.util.ArrayList;

public class test{
public static void main(String[] args) throws IOException{
String regex = "[\W&&\S&&[^\pP]]+";
String content =" In the end, the superintendents agreed to provide the data we sought, which is, after all, public information. There is, in our view, no real dispute here, we are all seeking the same thing, which is schools that better serve our children and our nation by encouraging students to tackle tough subjects under the guidance of gifted teachers. And if we keep working toward that goal, someday, perhaps a list won't be necessary.注"
+ "意:此部分试题请在答卡1上作答."
+ "1. Fifty years ago. big. Modern. Suburban high schools were established in the hope of __________.";
ArrayList rtext = new ArrayList ();
Matcher matcher = Pattern.compile(regex).matcher(content);
while(matcher.find()){
rtext.add(matcher.group(0));
}
for(String i:rtext){
System.out.print(i+" ");
}
}
}

我也觉得正则表达式好点

附:校验字符的表达式

1 汉字:^[\u4e00-\u9fa5]{0,}$

2 英文和数字:^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$

3 长度为3-20的所有字符:^.{3,20}$

4 由26个英文字母组成的字符串:^[A-Za-z]+$

5 由26个大写英文字母组成的字符串:^[A-Z]+$

6 由26个小写英文字母组成的字符串:^[a-z]+$

7 由数字和26个英文字母组成的字符串:^[A-Za-z0-9]+$

8 由数字、26个英文字母或者下划线组成的字符串:^\w+$ 或 ^\w{3,20}$

9 中文、英文、数字包括下划线:^[\u4E00-\u9FA5A-Za-z0-9_]+$

10 中文、英文、数字但不包括下划线等符号:^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$

11 可以输入含有^%&',;=?$\"等字符:[^%&',;=?$\x22]+

12 禁止输入含有~的字符:[^~\x22]+

我再补充一下content的内容是测试用的。起作用的是String regex = "[\W&&\S&&[^\pP]]+";
和Matcher matcher = Pattern.compile(regex).matcher(content);

java:汉字正则 String reg = "^[\u4e00-\u9fff]+$";
英文正则String reg = "^[a-zA-Z]+$";

试试这个吧,汉字占两个字符,且ASCII码小于零,直接把小于零的字符输出就行。
代码如下:
#include
#include
char str[100];
int main(){
scanf("%s",str);
int length=strlen(str);
for(int i=0;i<length;i++){
if(str[i]<0)
printf("%c",str[i]);
}
return 0;
}