cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in replaceing the text in the inputstream

Former Member
0 Kudos

Hello !!! <for program : str1.replaceAll(" & l t ;", "<");>

I am trying to replace the every occurrence of text " & l t ;" to " <" in the input data in and return the converted text to the OutputStream out. When I tried to use the below code for replacing the text, it dint really replace anything. Can anyone help me to figure out my mistake ?

Whenever I was trying to use str.replace all in the problem, my question was getting unformatted (you can see that in my last thread )

=======================================================

public void execute(InputStream in, OutputStream out){

StringBuffer str = new StringBuffer(8000);

String str1;

try {

int c;

while ((c = in.read()) != -1)

{

str.append((char)c );

}

str1 = str.toString();

<replace this space with the replace statement defined in the start of the thread>

byte[] byteArray = str1.getBytes();

ByteArrayOutputStream out1 = new ByteArrayOutputStream(byteArray.length);

try

{

out.write(byteArray);

} catch(Exception e)

{

e.printStackTrace();

}

out.flush();

} catch (Exception e) { }

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

First parameter of replaceAll method is a regular expression. In your case you passed in a string which includes the reserved key for regular expression. you need to polish your regular expression.

Former Member
0 Kudos

Hello Peeru,

I think I see what the problem might be:

The method call str1.replaceAll() will not modify the String str1.

Instead, it will return a new String, so you should write something like


str1 = str1.replaceAll( ... , ...)

Hope this helps; best regards,

Jens