2016-02-16 20:07:51 +01:00
|
|
|
package fr.pandacube.java.util;
|
|
|
|
|
|
|
|
public class StringUtil {
|
2016-07-14 14:22:23 +02:00
|
|
|
public static String formatDouble(double d) {
|
|
|
|
if (d == (long) d) return String.format("%d", (long) d);
|
|
|
|
else
|
|
|
|
return String.valueOf(d);
|
2016-02-16 20:07:51 +01:00
|
|
|
}
|
2016-07-14 14:22:23 +02:00
|
|
|
|
2016-02-16 20:07:51 +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>
|
|
|
|
*/
|
2016-07-14 14:22:23 +02:00
|
|
|
public static int char_count(CharSequence s, char c_match) {
|
2016-02-16 20:07:51 +01:00
|
|
|
char[] chars = s.toString().toCharArray();
|
|
|
|
int count = 0;
|
|
|
|
for (char c : chars)
|
2016-07-14 14:22:23 +02:00
|
|
|
if (c == c_match) count++;
|
2016-02-16 20:07:51 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|