import java.util.regex.Matcher; import java.util.regex.Pattern;
public class Test
{
public static void main(String arg[])
{
String s = "abc 123 456";
System.out.println(s);
while(true){
int index = s.indexOf(" ");
if(index > 0){
s = s.replaceAll(" "," ");
}else{
break;
}
}
System.out.println(s);
}
public static String replace(String inputStr, String replaceStr) {
Pattern p = Pattern.compile(" +");
Matcher m = p.matcher(inputStr);
return m.replaceAll(replaceStr);
}
}
没有评论:
发表评论