how to copy a string and replace all the spaces with tabs
i attempted this program as follows but am being asked that i do not copy a string. can anyone help
Code:
public class stringCopy {
public stringCopy() {
// TODO Auto-generated constructor stub
}
public String CopyString(String s){
String grt= new String();
return s.replaceAll("\\s+", "\t");
}
public String subString(String s,String sub){
String str[]=new String[10];
if ((s!=null)&&(sub!=null)){
s.replaceAll(sub, "");
for (int i = 0; i < str.length; i++) {
str[i]= s.replaceAll(sub, "");
}
}
return s.replaceAll(sub, "");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
stringCopy str = new stringCopy();
System.out.println(str.CopyString("Strings are good to work with"));
System.out.println(str.subString("Strings are good to work with","work"));
}
}
Re: how to copy a string and replace all the spaces with tabs
Quote:
am being asked that i do not copy a string
What does that mean?
What does your code do now and what do you want it to do?
Show what it outputs and explain what is wrong with that output.