mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-04-21 02:56:24 +02:00
27 lines
781 B
Java
27 lines
781 B
Java
package inf112.fiasko.roborally.utility;
|
|
|
|
/**
|
|
* This class helps with tasks related to string manipulation
|
|
*/
|
|
public final class StringUtil {
|
|
|
|
private StringUtil() {
|
|
}
|
|
|
|
/**
|
|
* Adds zeros to a number until it reaches a set length and converts it to a string
|
|
*
|
|
* @param number The number to add zeros to
|
|
* @param zeros The number of characters in the output
|
|
* @return The number as a string with necessary leading zeros
|
|
*/
|
|
public static String addLeadingZeros(int number, int zeros) {
|
|
StringBuilder numberAsString = new StringBuilder(String.valueOf(number));
|
|
for (int i = numberAsString.length(); i < zeros; i++) {
|
|
numberAsString.insert(0, "0");
|
|
}
|
|
return numberAsString.toString();
|
|
}
|
|
|
|
}
|