Results 1 to 3 of 3

Thread: Replace carriage return into <BR>?

  1. #1
    dereklyw
    Guest

    Question Replace carriage return into <BR>?

    Is there any easiest way to replace any carriage return in a String into "<BR>" when formatting the output to HTML?

    I know there is a method of String called "replaceAll" but seems only available since JDK 1.4

    Derek.

  2. #2
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    There maybe an easier way but this'll do it just as well...
    Code:
    public static String replaceAll(String theString, String oldString, String newString)
    {
    	String a;
    	String b;
    
    	int index = theString.indexOf(oldString);
    	
    	while(index != -1)
    	{
    		a = theString.substring(0, index);
    		b = theString.substring(index + oldString.length());
    		
    		theString = a + newString + b;
    		index = theString.indexOf(oldString);
    	}
    	
    	return theString;
    }
    Mrs K
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  3. #3
    dereklyw
    Guest

    Talking

    thanks a lot

Posting Permissions

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



Click Here to Expand Forum to Full Width