0

i want to format the colons in the below string. After printing the below string, the colons are misplaced.

static final String BODY    =  "Message : "+ message
            +"\r\n"+"Contact                : "+Name 
            +"\r\n"+"Contact Phone          : "+Mobile
            +"\r\n"+"Contact Email          : "+Email 
            +"\r\n"+"Home Location          : "+Address 
            +"\r\n\n"+VPROVIDOR ;

Actual Output -

Contact : Mahesh
Contact Phone : +919999999999
Contact Email : support@support.com
Home Location : Parathe wali gali

Expected Output -

enter image description here

Mohit Agrawal
  • 323
  • 4
  • 13

1 Answers1

1

Use String.format:

String.format("%30s:\r\n%30s:\r\n%30s:\r\n%30s:\r\n%30s:\r\n", message, name, mobile, email, address);

You can change the alignment by using a pattern like %-30s.

More information on the options you can find the javadoc.

john16384
  • 7,800
  • 2
  • 30
  • 44