How to format a String with other elements using format ()

4

I would like to know how to format a String 08041995 on 04/08/1995 using the format () method in Java

    PrintStream ps = new PrintStream(arq);
    String valor = "250,35";
    ps.format("R$ "+"%s", valor);
    ps.flush();

I was able to insert a String (R $) at the beginning of the String (value), but insert elements from a String, like the bars ... I do not know.

How to do it? Thanks!

    
asked by anonymous 30.10.2015 / 21:33

1 answer

2

You will not be able to use String.format for this, but you can break the string in 3 parts (using substring ) to do so:

String valor = "08041995";
String formatado = valor.substring(0, 2) + "/" +
                   valor.substring(2, 4) + "/" +
                   valor.substring(4, 8);
    
30.10.2015 / 21:45