This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 请问这个JAVA程序怎么写啊?多谢!编写一个JAVA函数匹配文件名。 函数有两个参数,一个是通常意义的文件通配符,另一个是文件名,函数判断该文件名是否符合指定通配符,例如通配符为 "*a*b", 文件名为 "aabab"时应返回TRUE,文件名为 "aababa"则
返回FALSE。
-writesome(penwrite);
2003-9-18
{215}
(#1374286@0)
-
Convert your "通配符"to RE first, then
System.out.println(java.util.regex.Pattern.matches(".*a.*b","aabab"));
-yuanzidan(原子弹);
2003-9-18
(#1374338@0)
-
您的意思我不太明白,函数究竟应该怎么写啊
那个 "*a*b", "aabab"只是所用参数举例,不能将其写到程序中啊。
-writesome(penwrite);
2003-9-18
(#1374357@0)
-
不是我不想帮你,我实在是觉的我说的够清楚的了。这可能是你的家庭作业吧?如果还没弄出来,看里面的CODE(JDK1.4+)。public static boolean test(String wildcard, String fileName)
{
return java.util.regex.Pattern.matches(java.util.regex.Pattern.compile
("([^a-zA-z0-9*?])").matcher(wildcard).replaceAll("\\\\$1").replaceAll
("\\[","\\\\[").replaceAll("\\*",".*").replaceAll("\\?",".{1}"),fileName);
}
-yuanzidan(原子弹);
2003-9-25
{334}
(#1385238@0)
-
野苹果,你这有BUG吧,怎么我想贴两个SLASH,就变一个了?我只好把SLASH DOUBLE 了,再试试。public static boolean test(String wildcard, String fileName)
{
return java.util.regex.Pattern.matches(java.util.regex.Pattern.compile
("([^a-zA-z0-9*?])").matcher(wildcard).replaceAll("\\\\\\\\$1").replaceAll
("\\\\[","\\\\\\\\[").replaceAll("\\\\*",".*").replaceAll("\\\\?",".{1}"),fileName);
}
-yuanzidan(原子弹);
2003-9-25
{362}
(#1385254@0)
-
再试试,public static boolean test(String wildcard, String fileName)
{
return java.util.regex.Pattern.matches(java.util.regex.Pattern.compile
("([^a-zA-z0-9*?])").matcher(wildcard).replaceAll("\\\\\\\\$1").replaceAll
("\\\\[","\\\\\\\\[").replaceAll("\\\\*",".*").replaceAll("\\\\?",".{1}"),fileName);
}
-yuanzidan(原子弹);
2003-9-25
{362}
(#1385265@0)
-
这个是对的。Rolia 修改贴的ESCAPE LOGIC 是对的,发新贴的ESCAPE LOGIC 有问题。
-yuanzidan(原子弹);
2003-9-25
(#1385286@0)
-
只能自己动手写个,记得在ACM96 有一道题目就是这样的,不过可比你这个复杂多了,你这就只有一个通配符,硬写都能把它给写出来。
-bobo123(bobo);
2003-9-19
(#1376088@0)
-
俺开始也觉着简单,可就是弄不出来,俺愚笨请您指点。
-writesome(penwrite);
2003-9-20
(#1377610@0)
-
有什么报酬
-bobo123(bobo);
2003-9-20
(#1377859@0)
-
http://pg9494.myrice.com/reference/wildcard.htm
-bobo123(bobo);
2003-9-20
(#1377956@0)
-
what he wanted is java code, if you really want to help him, could you please do some concrete job? What you have done isjust like many of our chinese fellow, that is, you just want to show how smart you are but do not want others to benefit from you.
-3hohoho(hohoho);
2003-9-24
{130}
(#1384516@0)