Ad
Strings
Code
Diff
  • public class ConfusedDouble {
      
    	public static String clearDouble(String str) {
    		if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
    			return ""; 
    		} 
    		String ret = str.replaceAll("[^0-9.]", "");
    		if(ret.length() == 1) return "";
    		return ret;
    	}
      
    }
    
    • //hacer que no funcione con una expresion regular con el caracter fin de cadena
    • public class ConfusedDouble {
    • public static String clearDouble(String str) {
    • public static String clearDouble(String str) {
    • if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
    • return "";
    • }
    • double num = Double.parseDouble(str.replaceAll("[^0-9.]", ""));
    • String result = Double.toString(num);
    • return result;
    • return "";
    • }
    • String ret = str.replaceAll("[^0-9.]", "");
    • if(ret.length() == 1) return "";
    • return ret;
    • }
    • }
Strings
Code
Diff
  • //hacer que no funcione con una expresion regular con el caracter fin de cadena
    
    public class ConfusedDouble {
      
       public static String clearDouble(String str) {
    		if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
          return ""; 
        } 
    		double num = Double.parseDouble(str.replaceAll("[^0-9.]", ""));
        String result = Double.toString(num);
        return result;
    	}
      
    }
     
    • //hacer que no funcione con una expresion regular con el caracter fin de cadena
    • public class ConfusedDouble {
    • public static String clearDouble(String str) {
    • if (str == null || str.length() == 0){
    • if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
    • return "";
    • }
    • double num = Double.parseDouble(str.replaceAll("[^0-9.]", ""));
    • String result = Double.toString(num);
    • return result;
    • }
    • }
Strings