在电子邮件中发送的java字符串的格式冒号

时间:2017-02-23 12:39:09

标签: java string formatting

我想格式化下面字符串中的冒号。打印下面的字符串后,冒号放错了位置。

System.DateTime

实际输出 -

联系人:Mahesh
联系电话:+919999999999
联系Email:support@support.com
主页地点:Parathe wali gali

预期产出 -

enter image description here

1 个答案:

答案 0 :(得分: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的选项的更多信息。