1
0

More than 1 year has passed since last update.

String.formatを使って空白以外の文字列埋め

Posted at

簡単に見つからなかったのでメモ。
これ以外にいい方法があれば教えてください。

末尾に「#」を付与し12桁にしたい場合

String.format("%-12s", "Test").replace(" ", "#");

いったん空白をセットし、
replaceメソッドで空白⇒"#"に書き換えています。

String.formatで直接"#"埋めすることができなかったです。
エスケープ「%」足しても駄目だったのでこちらの方法を使用しました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0