关于JAVA中split()函数遇到的一点问题
来源:互联网 发布:oauth独立域名 编辑:程序博客网 时间:2024/04/30 07:25
很简单的,就是想分割一个文件路径字符串,取它的扩展名。
String file=new String("c:\\test\\file.exe");
String[] temp = file.split(".");
程序运行到这里,就异常终止了。想想以前用split分割很多种符号,都没问题。随手试了试split("\\"),依然失败。又换了其他的各种符号":"、"##"等等却又没问题。难道"."和"\\"有什么不对么?
在仔细看看JDK的文档:
String[] java.lang.String.split(String regex)
split
public String[] split(String regex)
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }
Parameters:
regex - the delimiting regular expression
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern
清清楚楚的写着参数是String regex,一个regular expression,正则表达式。哎,以前没认真看过,一直当成普通的字符串在用了,只是运气好,恰好没出错。知错就改:
改成String[] temp = file.split("\\.");或者String[] temp = file.split("[.]");就可以了。至于那个"\\"分割的话,用String[] temp = file.split("\\\\");就可以了。
String file=new String("c:\\test\\file.exe");
String[] temp = file.split(".");
程序运行到这里,就异常终止了。想想以前用split分割很多种符号,都没问题。随手试了试split("\\"),依然失败。又换了其他的各种符号":"、"##"等等却又没问题。难道"."和"\\"有什么不对么?
在仔细看看JDK的文档:
String[] java.lang.String.split(String regex)
split
public String[] split(String regex)
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }
Parameters:
regex - the delimiting regular expression
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern
清清楚楚的写着参数是String regex,一个regular expression,正则表达式。哎,以前没认真看过,一直当成普通的字符串在用了,只是运气好,恰好没出错。知错就改:
改成String[] temp = file.split("\\.");或者String[] temp = file.split("[.]");就可以了。至于那个"\\"分割的话,用String[] temp = file.split("\\\\");就可以了。
- 关于JAVA中split()函数遇到的一点问题
- JAVA中split()关于.的问题
- 关于 VS2010 使用中遇到的一点小问题
- 关于ActivityGroup使用过程中遇到的一点问题
- 关于ActivityGroup使用过程中遇到的一点问题
- 关于Spring websocket 开发中遇到的一点问题
- 关于Java中String类的split(String regex)方法的一点困惑
- 关于java中String类型的split方法问题
- Java中split函数分割中英文的一些问题
- Java中Split函数的用法技巧 结果异常问题
- Java 中 split 函数分割的特别问题
- 关于split的一点注意事项
- java 关于split函数
- oracle中关于substr()函数的一点问题
- 关于java.split问题
- 关于split中字符串的问题
- Java中String.split()用法的一点经验
- JAVA中String.split()解析字符串的一点细节
- Oracle笔记_基于样例表的更多查询练习
- 这一夜我们只说CreateCompatibleDC
- Quartz 定时器
- RHEL4在VMware虚拟机中扩大linux硬盘空间
- 音乐播放器
- 关于JAVA中split()函数遇到的一点问题
- dc tracking
- 关于(十六进制值 0x00)是无效的字符
- error LNK2019: 无法解析的外部符号_imp__MessageBoxA@16,该符号在函数 _WinMain@16 中被引用
- 安卓动态菜单
- eclipse不能创建java虚拟机-解决方法
- Windows7 C盘空间越来越小处理方法
- Windows上手动卸载Sybase
- IplImage结构体