Work needs to optimize the code in the Chinese warning language and exception information, it is more, so wrote a program specifically from the code to extract Chinese strings.
Java, simple, put up memo
Package Com.extractstr.app;import Java.io.*;import Java.util.*;import java.util.regex.matcher;import java.util.regex.pattern;/** * search string and output to console */public class Extractstr {public static string gethelpstring (string[] args {String result = String.Format ("%s [path]", New object[]{"a"}); return result; } private void GetFiles (String rootpath, final string fileext, list<file> fileList) {file F =new file (root Path); File[] List=f.listfiles (new FileFilter () {@Override public boolean accept (File f) { boolean ret = f.isdirectory () | | (F.isfile () && f.getname (). EndsWith (Fileext)); return ret; } }); for (File fn:list) {if (Fn.isdirectory ()) {This.getfiles (Fn.getabsolutepath (), Fileext, Filelis T); }else{Filelist.add (FN); }}} public list<file> run (string rootpath, String fileext) { list<file> result = new linkedlist<file> (); This.getfiles (RootPath, fileext, result); return result; } public list<string> Parsersourcefile (list<string> patternlist, file file, int minicharcount) throws Excep tion {list<string> result = new linkedlist<string> (); BufferedReader r = new BufferedReader (new FileReader (file)); char[] buffer = new char[(int) file.length ()]; R.read (buffer, 0, (int) file.length ()); String Text=new string (buffer, 0, buffer.length); for (String patternstr:patternlist) {//pattern Pattern = pattern.compile ("\" (. *) \""); Pattern pattern = pattern.compile (PATTERNSTR); Matcher matchers= pattern.matcher (text); while (Matchers.find ()) {String t=matchers.group (); if (T.length () >=minicharcount) Result.add (t); }} return result; } public static void MaIn (String []args) {if (args.length==0) {StringBuilder sb = new StringBuilder (). Appen D ("No valid source code path required for Search"). Append ("\ n"). Append (extractstr.gethelpstring (args)); System.out.println (Sb.tostring ()); System.exit (1); } list<string> searchfolders=new arraylist<string> (100); for (int i=0; i<=args.length-1;i++) {file F=new file (Args[i]); if (!f.isdirectory () | |!f.exists ()) continue; Searchfolders.add (F.getabsolutepath ()); } list<string> patternlist = new linkedlist<string> (); Patternlist.add ("' ([\\u4e00-\\u9fa5]+) '); Patternlist.add ("\" ([\\u4e00-\\u9fa5]+) \ ""); Extractstr es = new Extractstr (); list<file> fileList = new arraylist<file> (1000); for (String sarchfolder:searchfolders) {list<file> t=es.run (Sarchfolder, ". php"); Filelist.addall (t); } set<string> outlist=new hashset<string> (); for (File f:filelist) {try{list<string> items=es.parsersourcefile (Patternlist, F, 12); Outlist.addall (items); }catch (Exception e) {e.printstacktrace (); }} for (String str:outlist) {System.out.println (str); } }}
Support for Chinese output of stitching string is not good, and the length of Chinese is limited (minimum 12 characters)
A Java class that extracts Chinese strings from source code