Pattern matchershowMethods

xiaoxiao2021-02-27  378

package string; //本篇主要解释了 Pattern 的简单用法 //p=Pattern.compile("regex"); //p.matcher(input.toString()).replaceAll(replacement) //"string".replaceAll(regex,replacement) //Matcher 的appendReplacement appendTail; //m=p.matcher(str); //StringBuffer sb=new StringBuffer(); //re=m.find(); //while(re){ //m.appendReplacement(sb,"sb"); //re=m.find(); //} //m.appendTail(sb) //最后 把 替换后的字符串str 放进sb中; //以下代码是利用反射 来找一个 类中的方法 import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.regex.Pattern; public class ShowMethods { private static Pattern p=Pattern.compile("\\w+\\."); public static void main(String[] args){ if(args.length<1){ System.exit(0); }else{ try { System.out.println(ShowMethods.class); Class<?> c=Class.forName(args[0]); Method[] methods=c.getMethods(); Constructor[] constructors=c.getConstructors(); if(args.length==1){ for(Method m:methods){ System.out.println(p.matcher(m.toString()).replaceAll("")); } for(Constructor con: constructors){ System.out.println("i am sb"); System.out.println(p.matcher(con.toString()).replaceAll("")); } }else{ } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
转载请注明原文地址: https://www.6miu.com/read-4093.html

最新回复(0)