當前位置:編程學習大全網 - 網站源碼 - cstring替換源代碼

cstring替換源代碼

導入Java . util . regex . matcher;

導入Java . util . regex . pattern;

公共類StringReplace {

public static final String regex = " \ \ {((?:\ \ w+))\ \ } ";

公共靜態最終字符串輸入= "{}...[A]B...[1{1}2]...{}";

公共靜態最終字符串替換= " & lt$1 >;

公共靜態void main(String[] args) {

模式p = pattern . compile(regex);

Matcher m = p.matcher(輸入);

string buffer buffer = new string buffer();

while (m.find()) {

m.appendReplacement(緩沖區,替換);

}

m.appendTail(緩沖區);

字符串result = buffer . tostring();

System.out.println(結果);

//結果是{}...[a & lt;A & gtb & ltB& gt;c]...[1 & lt;1 & gt;2]...{}

}

}

  • 上一篇:opengl導入obj模型全黑
  • 下一篇:冰雪之城能不能申請君臨號
  • copyright 2024編程學習大全網