package com.haxademic.core.text;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import com.haxademic.core.app.P;

public class StringFormatter {

	public static String timeFromSeconds( int seconds, boolean showHours ) {
		int h = (int) Math.floor(seconds / 3600f);
		int m = (int) Math.floor(seconds % 3600f / 60f);
		int s = (int) Math.floor(seconds % 3600f % 60);
		String hStr = (h < 10 ? "0" : "") + h;
		String mStr = (m < 10 ? "0" : "") + m;
		String sStr = (s < 10 ? "0" : "") + s;
		if( showHours == true ) {
			return hStr + ':' + mStr + ':' +sStr;
		} else {
			return mStr + ':' +sStr;
		}
	};

	public static String formatTimeFromSeconds( int seconds ) {
		int minutes = P.floor( seconds / 60f );
		int secondsOnly = seconds % 60;
		String secondsText = ( secondsOnly < 10 ) ? "0"+secondsOnly : ""+secondsOnly;
		String minutesText = ( minutes < 10 ) ? "0"+minutes : ""+minutes;
		return minutesText+":"+secondsText;
	}
	
	public static String timeFromMilliseconds( int millies, boolean showHours ) {
		return StringFormatter.timeFromSeconds( (int) Math.round( millies * 0.001f ), showHours );
	}
	
	public static String formattedDecimal(String number) {
		double amount = Double.parseDouble(number);
		DecimalFormat formatter = new DecimalFormat("#,###.00");
		return formatter.format(amount);
	}
	
	public static String formattedInteger(int number) {
		return NumberFormat.getInstance().format(number);
	}
	
	public static String toAlphaNumericChars(String str) {
		return str.replaceAll("[^A-Za-z0-9.]", "");
	}
	
	public static String toNumericChars(String str) {
		return str.replaceAll("[^0-9.-]", "");
	}
	
	public static String paddedNumberString(int size, int val) {
		return String.format("%0"+size+"d", val);
	}
	
	public static String uniqueCharactersInString(String input) {
		String result = "";
		for (int i = 0; i < input.length(); i++) {
			char letter = input.charAt(i);
			if(result.indexOf(letter) == -1) result = result.concat(Character.toString(letter));
		}
		return result;
	}

}

@@ -1532,32 +1532,266 @@
 9.%5D%22, %22%22);%0A%09%7D%0A%09%0A
+%09public static String toAlphaNumericCharsNoDecimal(String str) %7B%0A%09%09return str.replaceAll(%22%5B%5EA-Za-z0-9%5D%22, %22%22);%0A%09%7D%0A%09%0A%09public static String toAlphaNumericCharsWithSpaces(String str) %7B%0A%09%09return str.replaceAll(%22%5B%5EA-Za-z0-9%5C%5Cs%5D%22, %22%22);%0A%09%7D%0A%09%0A
 %09public static S

Add more string cleaning methods