public class StringUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static char[] |
hexChars |
Modifier | Constructor and Description |
---|---|
private |
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
bytesToHex(byte[] in) |
static java.lang.String |
escapeForCSV(java.lang.String input)
escapeForCSV
given a string, replace any occurances of " with double "'s, and return it surrounded in "'s
|
static java.lang.String |
escapeForXML(java.lang.String input)
Given a string, escape any < > & ' " characters for XML.
|
static int[] |
extractInts(java.lang.String s)
Convert a sequence of integers in a string into an array of ints.
|
static java.lang.String |
leftPad(java.lang.String text,
int size)
Pad some text on the left (i.e., right-align it) until it's a specified width.
|
static java.lang.String |
shortedFileName(java.io.File f,
java.lang.Integer charactersallowed)
Returns a user friendly string of the filename for a file shortened to the number of characters specified.
|
static java.lang.String[] |
splitBy(java.lang.String text,
char sep)
Split some text, using an arbitrary separator character.
|
static java.lang.String[] |
splitByLines(java.lang.String text)
Split some text into lines.
|
static java.lang.String |
substitute(java.lang.String str,
java.lang.String source,
java.lang.String target)
In a string, replace one substring with another.
|
public static java.lang.String leftPad(java.lang.String text, int size)
text
- string to padsize
- length of resulting stringpublic static java.lang.String shortedFileName(java.io.File f, java.lang.Integer charactersallowed)
f
- charactersallowed
- public static java.lang.String[] splitByLines(java.lang.String text)
"a\nb\nc"
becomes String[]
{"a","b","c"}
.text
- the text, separated by '\n'
charspublic static java.lang.String[] splitBy(java.lang.String text, char sep)
text
- the textsep
- the separator character to watch forpublic static int[] extractInts(java.lang.String s)
For example, extractInts("1 2 3") = int[] { 1, 2, 3 }.
Bug: what happens if the string isn't parseable?
s
- the string to parsepublic static java.lang.String escapeForXML(java.lang.String input)
input
- a stringpublic static java.lang.String escapeForCSV(java.lang.String input)
input
- a stringpublic static java.lang.String substitute(java.lang.String str, java.lang.String source, java.lang.String target)
If str contains source, return a new string with (the first occurrence of) source replaced by target.
If str doesn't contain source (or str is the empty string), returns str.
Think: str ~= s/source/target/
This is like Java 1.4's String.replaceFirst() method; when I decide to drop support for Java 1.3, I can use that method instead.
str
- the base stringsource
- the substring to look fortarget
- the replacement string to usepublic static java.lang.String bytesToHex(byte[] in)