gpt4 book ai didi

java - 使用 String.format 时如何缩进新行?

转载 作者:行者123 更新时间:2023-11-30 06:04:58 24 4
gpt4 key购买 nike

我目前正在开发一个项目并使用基于文本的日志系统。我以“Test String\nTest String2\n Test String3”的形式向该方法提供我的字符串。

这就是字符串格式的样子。

adminWriter.newLine();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String currDateTime = dateFormat.format(date);

adminWriter.write(String.format("%-20s | %-50s", currDateTime, text));

该方法的调用方式如下...

Start.scribe.adminToDoWrite("User: "+this.riderID
+"\nTo Delete Horse: "+this.horses[row].getHorseID()
+"\nHorse Name: "+this.horses[row].getHorseName());

当前的输出如下所示

{Date And Time} | User: (Number)
To Delete Horse: (Number)
Horse Name: (Name)

有办法让它看起来像这样吗?这样每个新行都会自动缩进到 String.format 规则吗?

{Date And Time} | User: (Number)
To Delete Horse: (Number)
Horse Name: (Name)

非常感谢

最佳答案

你需要改变

来自:

Start.scribe.adminToDoWrite("User: "+this.riderID
+"\nTo Delete Horse: "+this.horses[row].getHorseID()
+"\nHorse Name: "+this.horses[row].getHorseName());

致:

Start.scribe.adminToDoWrite("User: "+this.riderID
+"\n To Delete Horse: "+this.horses[row].getHorseID()
+"\n Horse Name: "+this.horses[row].getHorseName());

关于java - 使用 String.format 时如何缩进新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51525856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com