what is the Java equivalent of sscanf for parsing values from a string using a known pattern?

后端 未结 8 843
梦如初夏
梦如初夏 2020-11-27 06:01

So I come from a C background (originally originally, though I haven\'t used that language for almost 5 years) and I\'m trying to parse some values from a string in Java. In

8条回答
  •  无人及你
    2020-11-27 06:47

    This is far from as elegant solution as one would get with using regex, but ought to work.

    public static void stringStuffThing(){
    String x = "17-MAR-11 15.52.25.000000000";
    String y[] = x.split(" ");
    
    for(String s : y){
        System.out.println(s);
    }
    String date[] = y[0].split("-");
    String values[] = y[1].split("\\.");
    
    for(String s : date){
        System.out.println(s);
    }
    for(String s : values){
        System.out.println(s);
    }
    

提交回复
热议问题