这是我的code..Help,我删除逗号前的数字,然后打印两个单词
for(int y=0;y<nso.length;y++)
{
File e=new File(nso[y]);
BufferedReader be=new BufferedReader(new FileReader(e));
String st,t;
while((st=be.readLine())!=null)
{
if(st.contains("ns"))
{
int offset=st.indexOf("(");
st=st.substring(offset+1, st.length()-3);
System.out.println(st);
ap.write(st);
ap.println("\n");
}
}
ap.close();
be.close();该文件包含
phone-6, This
know-8, I
looking-5, you
phone-14, this-
graphics-2, has-发布于 2014-10-28 09:28:54
您可以在这里使用st.replaceAll(regex,"")将所有数字替换为""。例如,String result=st.replaceAll("[0-9]+",""); System.out.println(result);
发布于 2014-10-28 09:23:34
我可以给你提供步骤
发布于 2014-10-28 09:24:04
使用regexp:
st.replaceAll("[0-9]","");这将用空字符串替换数字。
如果你想摆脱-
st.replaceAll("[0-9\\-]","");这是一种假象。有关详细信息,此页面是有用的:http://www.vogella.com/tutorials/JavaRegularExpressions/article.html
https://stackoverflow.com/questions/26604601
复制相似问题