當我運行代碼bellow時,我得到錯誤:「(TyperError)f未定義」 當我編譯OFB風格時出現此錯誤。 當我使用PRETTY風格時,它正在正常工作。字符串replaceAll GWT和OBF編譯模式
GWT版本:2.4
public static String replaceCommaWithDotInFloat(String text) {
String result = replaceCommaWithDot(DATA_DELIMITER, text, DATA_DELIMITER);
result = replaceCommaWithDot(LINE_DELIMITER, result, LINE_DELIMITER);
result = replaceCommaWithDot(LINE_DELIMITER, result, DATA_DELIMITER);
result = replaceCommaWithDot(DATA_DELIMITER, result, LINE_DELIMITER);
return result;
}
private static String replaceCommaWithDot(String startsWith, String text, String endsWith) {
return text.replaceAll(startsWith + "([+-]?\\d+),(\\d+)" + endsWith, startsWith + "$1.$2" + endsWith);
}
我不知道爲什麼你所得到的錯誤,而是直接插入串入正則表達式是個壞消息。嘗試使用Pattern.quote在正則表達式param中轉義startsWith和endsWith,並使用Matcher.quoteReplacement將它們轉義爲替換字符串。 – nhahtdh