Multiline strings concatenation in Java -


i'm looking help. easiest way concatenate multiline strings in java , print after ?

for example : i've got 2 strings :

string turtle1 = "         _\r\n     .-./*)\r\n   _/___\\/\r\n     u u\r"; string turtle2 = "         _\r\n     .-./*)\r\n   _/___\\/\r\n     u u\r"; 

and want result in java eclipse console :

         _            _      .-./*)       .-./*)    _/___\/      _/___\/      u u          u u 

i've try algorithms divide strings in differents parts , after re-concatenate it. without success. know there stringbuffer class , stringbuilder class after research, didn't found correspond need.

thanks in advance help.

not pretty works:

string turtle1 = "         _\r\n     .-./*)\r\n   _/___\\/\r\n     u u\r\n"; string turtle2 = "         _\r\n     .-./*)\r\n   _/___\\/\r\n     u u\r\n"; string[] turtle1lines = turtle1.split("\r\n"); string[] turtle2lines = turtle2.split("\r\n"); stringbuilder sb = new stringbuilder(); int turtle1width = 0; (int = 0; < 4; i++) {     if (turtle1lines[i].length() > turtle1width) {         turtle1width = turtle1lines[i].length();     } } (int = 0; < 4; i++) {     sb.append(turtle1lines[i]);     (int j = turtle1width - turtle1lines[i].length(); j > 0; j--) {         sb.append(' ');     }     sb.append(turtle2lines[i]);     sb.append("\r\n"); } string turtles = sb.tostring(); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -