on 04-11-2008 3:28 PM
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) { }
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.