2017-02-23 58 views
0

我想在下面的字符串中格式化冒號。打印下面的字符串後,冒號被錯位。在E-mail中發送的用於java字符串的格式冒號

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 ; 

實際輸出 -

聯繫人:馬赫什
聯繫電話:919999999999
聯繫電子郵件:[email protected]
當前位置:Parathe窪里加利

預期輸出 -

enter image description here

+0

你可以添加你的實際結果和預期的結果嗎? –

+0

@MincongHuang補充說 –

回答

1

使用String.format

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

您可以通過使用一種模式像%-30s更改對齊。

有關您可以找到javadoc的選項的更多信息。