Search code examples
javatext-alignment

How to move String block of text xTab spaces to the right in Java?


If I have got a whole block of text as a String, which contains several new-lines.

For example: System.out.println(myString) would give:

<http-request>
  <param1>value</param>
  <param2>value</param>
</http-request>

And what I want to do is space the whole block three tab spaces to the right...

What is the best way to get this done?


Solution

  • Not tried in code but sounds like the replace(regex, string) should work. Just go for replace("\n", "\n\t\t\t") -> one \t per tab space.

    (replace from String's standardlib)