Results 1 to 2 of 2
  1. #1
    stevisto is offline Member
    Join Date
    Sep 2011
    Rep Power

    Default 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
    Java 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"));
    Last edited by Norm; 09-15-2011 at 01:51 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: how to copy a string and replace all the spaces with tabs

    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.

Similar Threads

  1. String.replace ?!
    By HearT.Hunt3r in forum New To Java
    Replies: 4
    Last Post: 08-22-2011, 03:04 AM
  2. Replace a cell with Spaces
    By Shyamz1 in forum New To Java
    Replies: 11
    Last Post: 11-07-2010, 03:37 PM
  3. How to display a String that contains more than one white spaces
    By thachun in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 09-27-2009, 09:16 AM
  4. Replies: 3
    Last Post: 08-20-2009, 03:57 PM
  5. Replace String
    By Raeghin in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts