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!
Printable View
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!
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();
}
}
Where's the text that you want to replace comming from? If it's just a function you want crptcblade's looks good. :)
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!
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!