gpt4 book ai didi

Java Formatter 指定文本的起始位置

转载 作者:行者123 更新时间:2023-11-30 05:12:18 31 4
gpt4 key购买 nike

我试图将字符串定位在一行上的某个起始位置,无论前一个文本在哪里结束。例如:

Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..

选项的解释从位置 30 开始,无论前面的文本如何。如何使用 java.util.Formatter 完成此任务?我已经使用宽度 (%30s) 和精度 (%.30) 参数进行了测试,但都没有提供所需的结果。

最佳答案

您可以使用“宽度”参数,如下所示:

    System.out.println(String.format("%-30s%s", "  -a, --all", "do not ignore entries starting with ."));
System.out.println(String.format("%-30s%s", " -A, --almost-all", "do not list implied . and .."));

编辑
如果您有兴趣,请完整概述。它一点也不大,格式化功能非常有限。
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax

关于Java Formatter 指定文本的起始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2993416/

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