Remove empty line from within Java text

Asked

Viewed 148 times

0

By manipulating a xml return of a service, I do the following manipulation in the file:

return xmlServico.replaceAll("job.coincidencia.vo.", "").replaceAll("RNSCoincidenciasMultiRamo_-", "").replaceAll("Coincidencia", "").replaceAll("<>", "").replaceAll("</>", "");

However, such replaces generated empty lines in the middle of the file and, although it seems simple, I am not able to remove these empty lines. I have tried using .replaceAll(" ", ""); but the empty lines are still there and it still takes away all the formatting from the xml.

  • Have you considered replacing all ' n' that are on a line that has no xml tags?

  • I find it simpler to use a specific lib to manipulate XML - in Java there are several. Making string replacements is very error prone, there is corner cases too much to be treated, something a lib can handle much better.

  • @Adrianogomes did this but was taking out all the xml formatting but in the end I ended up doing more or less that same. Thanks for the help, friend.

  • @hkotsubo Thanks for your attention, friend. I ended up solving otherwise.

1 answer

0

I solved basically with a replace even. So: .replaceAll("(?m)^[ \t]*\r?\n", "")

Thanks for all your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.