我正在使用此代码来分隔下一行并留出空间。

String sms="Name:"+name+ System.getProperty ("line.separator")+System.getProperty
   ("line.separator")+"ContactNumber:"+contactnumber+ System.getProperty
   ("line.separator")+"Quantity:"+quantity+System.getProperty
   ("line.separator")+"Number.of.Pcs:"+noofpieces+System.getProperty
   ("line.separator")+"Date and Time:"+dateandtime
   +System.getProperty ("line.separator")+"Delivary
   Address:"+deliveryaddress;

最佳答案

您可以使用StringBuilder实例,然后使用附加到StringBuilder的换行符。例如:

StringBuilder sb = new StringBuilder();
sb.append("Name: ").append(name);
sb.append("\n"); // for a new line.


无论如何,我强烈建议您使用StringBuilder附加到非常大的String上。

另外,您也可以使用System.lineSeparator();。但是,这可能仅在Java和JVM与Java 7一起在Java中起作用,而在Android中不起作用(因此,我肯定会检查一下。)

09-30 14:30
查看更多