本文介绍了从名称解析字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从文件名中解析特定名称.
I am trying to parse the certain name from the filename.
文件名的示例是
xs_1234323_00_32
sf_12345233_99_12
fs_01923122_12_12
我用String parsedname= child.getName().substring(4.9)
从第一行中取出1234323.取而代之的是,如何格式化上面的3以仅输出中间的数字(两个_之间)?使用split
吗?
I used String parsedname= child.getName().substring(4.9)
to get the 1234323 out of the first line. Instead, how do I format it for the above 3 to output only the middle numbers(between the two _)? Something using split
?
推荐答案
String [] tokens = filename.split("_");
/* xs_1234323_00_32 would be
[0]=>xs [1]=> 1234323 [2]=> 00 [3] => 32
*/
String middleNumber = tokens[2];
这篇关于从名称解析字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!