using parenthesis replaceAll method Java

前端 未结 1 672
余生分开走
余生分开走 2021-01-27 17:42

I would like to change a word in a sentence, but the word has parenthesis. I keep it in the String variable. Inside of the variable st I have

man

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 18:36

    I believe you wanted to use String#replace() (not replaceAll), this

    String EDC = "query(MT0, P0) :- not(manages(P0,MT0)), "
        + "ins_manages(P0,MT0), not(physician(P0)), not(ins_physician(P0))";
    String queryPart = "managesa";
    EDC = EDC.replace("manages(P0,MT0)", queryPart);
    System.out.println(EDC);
    

    Output is

    query(MT0, P0) :- not(managesa), ins_managesa, not(physician(P0)), not(ins_physician(P0))
    

    0 讨论(0)
提交回复
热议问题