2014-09-04 36 views
0

我需要關於如何在更新數據庫之前從字符串中刪除$符號的幫助目前在我的應用程序中,默認情況下從結尾添加$作爲第一個字符。我需要知道如何刪除它,因爲更新數據庫時遇到大十進制錯誤。

String postagePaid = (String) request.getParameter("tPostagePaid"); 
      String insuranceFees = (String) request.getParameter("tInsuranceFees"); 
      String registeredFees = (String) request.getParameter("tRegisteredFees"); 
      String codFees = (String) request.getParameter("tCODFees"); 
      String insRegisteredCODFees = (String) request.getParameter("tInsuranceFees"); 
      System.out.println("insurance Fee: " + insuranceFees); 
      if (postagePaid != null && !insuranceFees.isEmpty()) { // postage paid amount 
       claim.setClPostagePaidAmt(new BigDecimal(postagePaid)); 
      } 
      if (insuranceFees != null && !insuranceFees.isEmpty()) { // Insurance Fees 
       claim.setClInsuranceFee(new BigDecimal(insuranceFees)); 
      } 
      if (registeredFees != null && !insuranceFees.isEmpty()) { // Registered Fees 
       claim.setClRegisteredFee(new BigDecimal(registeredFees)); 
      } 
      if (codFees != null && !insuranceFees.isEmpty()) { // COD Fees 
       claim.setClCodFee(new BigDecimal(codFees)); 
      } 
      claim.setClInsRegCodAmt(null); 
+1

http://stackoverflow.com/questions/4576352/java-remove-all-occurrences-of-char-from-string – Pienterekaak 2014-09-04 15:43:52

+0

那麼實際的問題是什麼?你是否嘗試過任何東西來代替'yourStr.replaceAll(「\\ $」,「」)「或任何東西? – SparkOn 2014-09-04 15:45:25

+1

只需執行'yourStr.replace(「$」,「」)'',避免在不需要時使用正則表達式。 – 2014-09-04 15:52:26

回答

1

您可以嘗試兩件事。

str = str.replace("$",""); 

OR

str = str.substring(1); 

原因
你只是要刪除的第一個字符。

相關問題