Discuss / Java / 交作业,各位有没有好的方法。。

交作业,各位有没有好的方法。。

Topic source

static void log(String text, LocalTime lt, String name, LocalDate ld) {
    Pattern p = Pattern.compile("\\[(\\{})]\\sstart\\s(\\{})\\sat\\s(\\{})...");    Matcher m = p.matcher(text);    String result = "";    System.out.println(m.matches());    if (m.matches()) {
        int m1 = m.start(1);        int m2 = m.start(2);        int m3 = m.start(3);        result = text.substring(0, m1) + lt.toString() + text.substring(m1 + 2, m2) + name
                + text.substring(m2 + 2, m3)
                + ld.toString() + text.substring(m3 + 2);    }
    System.out.println(result);}

康小peng

#2 Created at ... [Delete] [Delete and Lock User]

你这没看懂,但是你用了解释器了,我们是通过别的方式实现解释器

  StringBuilder sb = new StringBuilder();

  String a1 = a.substring(0, 1);

  String a2 = a.substring(3, 11);

  String a3 = a.substring(13, 17);

  String a4 = a.substring(19, a.length());

  sb.append(a1).append(lt.toString()).append(a2).append(b).append(a3).append(ld.toString()).append(a4);

  System.out.println(sb.toString());


  • 1

Reply