2014-12-26 00:12:28 +01:00
|
|
|
package net.mc_pandacraft.java.util;
|
|
|
|
|
|
|
|
public class StringUtil {
|
|
|
|
public static String formatDouble(double d)
|
|
|
|
{
|
|
|
|
if(d == (long) d)
|
|
|
|
return String.format("%d",(long)d);
|
|
|
|
else
|
|
|
|
return String.valueOf((float)d);
|
|
|
|
}
|
2015-01-22 09:32:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param s Chaine de caractère à parcourir
|
|
|
|
* @param c_match le caractère dont on doit retourner le nombre d'occurence
|
|
|
|
* @return nombre d'occurence de <b>c_match</b> dans <b>s</b>
|
|
|
|
*/
|
|
|
|
public static int char_count(CharSequence s, char c_match)
|
|
|
|
{
|
|
|
|
char[] chars = s.toString().toCharArray();
|
|
|
|
int count = 0;
|
|
|
|
for (char c : chars)
|
|
|
|
if (c == c_match)
|
|
|
|
count++;
|
|
|
|
return count;
|
|
|
|
}
|
2014-12-26 00:12:28 +01:00
|
|
|
}
|