请问一个截取字段的问题 比如 String a = "5分钟";这个5分钟有可能是10分钟,或者20分钟这种不确定的数。如何只截取数字部分呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String str = "35分钟";int index = str.indexOf("分钟");String result = "0";if( index > 0 ){ result = str.subString(0,index);}System.out.println(result); String[] strArray = str.split("分钟");or String strOutput = str.replaceAll("分钟", ""); "分钟"2个字的长度是固定的,所以....a.substring(0, a.length()-2) 这样 public static void main(String[] args) { String str = "拉拉5分钟呵呵10分钟"; String regex = "[\\d]+分钟"; Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(str); while(m.find()) { String matched = m.group(); System.out.println(matched.substring(0,matched.indexOf("分钟"))); } } 用正则表达式吧:import java.util.regex.Matcher;import java.util.regex.Pattern;public class RegTest{ public static void main(String[] args){ Pattern p = Pattern.compile("[0-9]+"); Matcher m = p.matcher("10分钟"); if(m.find()){ System.out.println(m.group()); } }} public static void main(String args[]) { String str = "*分钟"; String target= str.replaceAll("分钟", ""); //System.out.println(target); } public class test{ public static void main(String args[]) { String str="523242分zhonga"; byte b[] = str.getBytes(); for(int i=0;i<b.length;i++) { System.out.println(""+i); System.out.println(b[i]); if(Character.isDigit(b[i])) continue; else b[i]=' '; } String str2= new String(b); str2=str2.trim(); System.out.println(str2); }} http://bbs.tarena.com.cn/去这里看看 enum中的values()方法 关于JMF里面setMediaTime()的几个问题 请问这个警告是什么意思,谢谢! 关于JAVA中的LOOP! 菜鸟求助! 请问这句话怎么错了,应该怎么写 ¥¥¥ JAVA中常用类有那些?我想重点学习--java新手 jsp做服务器端,.net做客户端的应用程序,能够实现吗? 我需要一些swing的c/s方面的源代码,请问谁知道哪里有的下载 为什么在win200下我用jb7写applet在网页上显示不了??? 请熟悉ANT的朋友帮忙解决一下!!!!! 如何把一个PDF文件变成序列化对象? 清理关键词 finalize
String str = "35分钟";
int index = str.indexOf("分钟");
String result = "0";
if( index > 0 )
{
result = str.subString(0,index);
}System.out.println(result);
or
String strOutput = str.replaceAll("分钟", "");
String str = "拉拉5分钟呵呵10分钟";
String regex = "[\\d]+分钟";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(str);
while(m.find()) {
String matched = m.group();
System.out.println(matched.substring(0,matched.indexOf("分钟")));
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class RegTest
{
public static void main(String[] args){
Pattern p = Pattern.compile("[0-9]+");
Matcher m = p.matcher("10分钟");
if(m.find()){
System.out.println(m.group());
}
}
}
public static void main(String args[]) {
String str = "*分钟";
String target= str.replaceAll("分钟", "");
//System.out.println(target);
}
{
public static void main(String args[])
{
String str="523242分zhonga";
byte b[] = str.getBytes();
for(int i=0;i<b.length;i++)
{
System.out.println(""+i);
System.out.println(b[i]);
if(Character.isDigit(b[i]))
continue;
else b[i]=' ';
}
String str2= new String(b);
str2=str2.trim();
System.out.println(str2);
}
}