Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace sequence of characters in java

Tags:

java

I am parsing a poorly structured rss feed, and some of the data that is being returned has <p>at in it. How can I replace all instance of <p>at with an empty space, using java?

I'm familiar with the .replace method for the String class, but I'm not sure how the regex expression would look. I tried inputString.replace("<p>at", "") but that didn't work.

like image 771
user1154644 Avatar asked Apr 29 '12 05:04

user1154644


1 Answers

Try this:

inputString = inputString.replace("<p>at", "");

Be aware that the replace() method does not modify the String in-place (as is the case with all methods in the String class, because it's immutable), instead it returns a new String with the modifications - and you need to save the returned string somewhere.

Also, the above version of replace() doesn't receive a regular expression as an argument, just the string to be replaced and its replacement.

like image 134
Óscar López Avatar answered Sep 19 '22 15:09

Óscar López