Search code examples
javastring.formatformat-string

Is there a "%"-symbol for Space in string.format()?


For new line the symbol is "%n"; how about space, is there a symbol for it?

I've searched for it on various websites but I couldn't find it.


Solution

  • You would just use a space, " ", and that's it. No magic here for this one.

    for example:

    String text = "%4d: %04x%n";  // note the space
    for (int i = 0; i < 100; i++) {
      System.out.println(text, i, i);
    }
    

    You comment:

    I am looking for the equivalent symbol mate.

    There is no equivalent symbol, and there's no need for one. This is likely why your Google search has yielded no fruit.