黑暗岁月
有一个string,如何查询其中是否有y和f字符?最黑暗的办法就是:
程序1:我知道if、for语句和charat()啊。
| class test{ public static void main(string args[]) { string str="for my money, the important thing "+"about the meeting was bridge-building"; char x='y'; char y='f'; boolean result=false; for(int i=0;i<str.length;i++){ char z=str.charat(i); //system.out.println(z); if(x==zy==z) { result=true; break; } else result=false; } system.out.println(result); } } |
| import java.util.regex.*; class regex1{ public static void main(string args[]) { string str="for my money, the important thing "+"about the meeting was bridge-building"; string regex="af"; //表示a或f pattern p=pattern.compile(regex); matcher m=p.matcher(str); boolean result=m.find(); system.out.println(result); } } |
| pattern p=pattern.compile(regex,pattern.case_insensitive); |
| public static pattern compile(string regex) { return new pattern(regex, 0); } |
| boolean result=pattern.compile(regex).matcher(str).find(); |
| import java.util.regex.*; class regex1{ public static void main(string args[]) { string str="for my money, the important thing "; string regex="ab*"; boolean result=pattern.compile(regex).matcher(str).find(); system.out.println(result); } }//ture |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器