日期:2014-05-20  浏览次数:20634 次

以空格为要求,按要求输出一段字符
假如输入一段luinx命令为单个命令,比如 "rz ",则输出 "^rz   *.* "
如果输入是多个命令,如 "rm   -rf ",则输出 "^rm   .*   -rf "
其它判断是多个命令还是单个命令主要以空格来区别(个人认为)

------解决方案--------------------
public String CreateString(String str){

String ss= " ";

for (int i=0;i <str.length();i++){
String s=str.substring(i, i+1);

if (s.equals( " ")){
ss=ss+s;
ss=ss+ "*.* ";
}
else{
ss=ss+s;
}
}

return ss;
}
------解决方案--------------------
String str= "rm -rf ";
str = str.replaceAll( "\\s+ ", "$0.* ");
System.out.println(str);

------解决方案--------------------
public class DateExample {
public static void main(String[] args) {

String str= "rm ";
String ss= " ";
String[] a = str.split( " ");
if(a.length==1){
ss = a[0]+ " *.* ";

}else{
for (int i=0;i <a.length-1;i++){
ss+=a[i]+ ".* ";

}
ss+=a[a.length-1];
}
System.out.println(ss);


}
}