ChestShop-3/com/Acrobot/Breeze/Utils/StringUtil.java
Acrobot 5908eb67fa - Added API (let's start with simple things first)
- Copied utilities from ChestShop-4
- Made code really, really nicer to read
- Made every external plugin's wrapper a listener, so it listens to events instead of being hard-coded.
2012-06-08 15:28:36 +02:00

55 lines
1.4 KiB
Java

package com.Acrobot.Breeze.Utils;
/**
* @author Acrobot
*/
public class StringUtil {
/**
* Capitalizes every first letter of a word
*
* @param string String to reformat
* @param separator Word separator
* @return Reformatted string
*/
public static String capitalizeFirstLetter(String string, char separator) {
string = string.toLowerCase();
String[] split = string.split(Character.toString(separator));
StringBuilder total = new StringBuilder(string.length());
for (String s : split) {
total.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(' ');
}
return total.toString().trim();
}
/**
* Capitalizes every first letter of a word
*
* @param string String to reformat
* @return Reformatted string
* @see com.Acrobot.Breeze.Utils.StringUtil#capitalizeFirstLetter(String, char)
*/
public static String capitalizeFirstLetter(String string) {
return capitalizeFirstLetter(string, ' ');
}
/**
* Joins a String array
*
* @param array array to join
* @return Joined array
*/
public static String joinArray(String[] array) {
StringBuilder b = new StringBuilder(array.length * 15);
for (String str : array) {
b.append(str).append(' ');
}
return b.toString();
}
}