Results 1 to 5 of 5

Thread: replace [resolved by crptcblade]

  1. #1

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    replace [resolved by crptcblade]

    I've got a char array which is about to be written.

    I want to replace any formfeeds with some text.

    How do I do that?

    performance is CRITICAL!
    Last edited by Mark Sreeves; Nov 15th, 2001 at 09:07 AM.
    Mark
    -------------------

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    performance is iffy, but here's what I got...
    Code:
    public class Test 
    {
    	public static void main(String[] args) 
    	{
    		char[] x = {'H','e','\f','l','0',};
    		char[] y = replaceChars(x, '\f', "Some Text");
    
    		System.out.println(y);
    	}
    
    	static char[] replaceChars(char[] origChars, char toReplace, String replaceWith)
    	{
    		StringBuffer strb = new StringBuffer(new String(origChars));
    
    		int x = (strb.toString()).indexOf(toReplace);
    
    		while (x > -1)
    		{
    			strb = strb.replace(x, x+1, replaceWith);
    			x = (strb.toString()).indexOf(toReplace);
    		}
    
    		return (strb.toString()).toCharArray();
    	}
    }
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

  4. #4

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Thanks for the suggestions I'll try and make use of it tomorrow when I'm back in the office.

    it really is horrific!
    The code is for use in a JSP custom tag
    The char array is being populated from an oracle database and is a long raw type.
    The string I want to replace thr form feed with is being passed as an atribute to the tag.

    What the hell is it all for I hear you ask!

    The JSP is a part of a report publishing system. The data in the database has form-feeds in it I need to swap these for the string <p class=pb>
    p.pb is then defined in a stylesheet with a page-break-before=always
    This is so the browser page-breaks correctly.

    If the data was stored as a string instead of Long Raw, I could do the substitution in the SQL.
    But is isn't so I can't!

    The form feed has to stay in the original data because we offer the user to download the file as plain text and so we don't want the css in there!
    Mark
    -------------------

  5. #5

    Thread Starter
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Thumbs up

    YES! YES! YES!


    Thanks crptcblade it works a treat!

    I think the performance should be OK because the slowest part of the process will the transmission of the data to the browser anyway

    Thanks again for your help!
    Mark
    -------------------

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