|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.autonomy.utilities.StringUtils
Library of functions used for working with Strings
Constructor Summary | |
StringUtils()
Constructor. |
Method Summary | |
static boolean |
atob(java.lang.String sKey,
boolean bDefault)
Coverts a string to a boolean or returns bDefault if this is not possible |
static double |
atod(java.lang.String sNumber,
double dDefault)
Coverts a string to a double or returns dDefault if this is not possible |
static float |
atof(java.lang.String sNumber,
float fDefault)
Coverts a string to a float or returns fDefault if this is not possible |
static int |
atoi(java.lang.String sNumber,
int nDefault)
Coverts a string to an int or returns nDefault if this is not possible |
static long |
atol(java.lang.String sNumber,
long nDefault)
Coverts a string to a long or returns nDefault if this is not possible |
static int |
binarySearch(java.lang.String[] saInput,
char cChar,
boolean bReturnNotFound)
Perform a binary search , finds the first element in sorted array saInput beginning with cChar or the first letter after cChar |
static int |
binarySearch(java.util.Vector vInput,
char cChar,
boolean bReturnNotFound)
Perform a binary search , finds the first element in sortedvector vInput beginning with cChar or the first letter after cChar |
static int |
binarySearch(java.util.Vector vInput,
java.lang.String sToFind,
boolean bReturnNotFound)
Perform a binary search , finds the first element in sorted vector vInput beginning with cChar or the first letter after cChar |
static java.lang.String |
combine(java.lang.String[] saInput,
java.lang.String sSplitCharacter)
Method to convert an array of Strings into a CSV |
static boolean |
containsIllegalChars(java.lang.String sTest)
Does a strValid and then returns true if the String contains " ' < > or illegal & |
static boolean |
containsNonAlphaNumericChars(java.lang.String sTest)
Does a strValid and then returns true if the String contains anything other than letters digits or underscores |
static java.lang.String |
decryptString(java.lang.String sToDecrypt)
decrypts a string |
static java.util.Enumeration |
deduplicate(java.lang.String[] as)
Remove any duplicated elements from the array |
static java.lang.String |
encryptString(java.lang.String sToEncrypt)
encrypts a string |
static java.lang.String |
ensureNoSeparatorAtEnd(java.lang.String sToSlash)
Removes any path.separator at the end of a string if there isn't one there already |
static java.lang.String |
ensureSeparatorAtEnd(java.lang.String sToSlash)
Puts a path.separator at the end of a string if there isn't one there already |
static java.lang.String |
getHTMLColorFromString(java.lang.String sToParse)
parses a string and looks for a HTML "#xxxxxx" type string |
static java.lang.String |
getImageNameFromString(java.lang.String sToParse)
parses a string and extracts an image name from a background="image.gif" string |
static java.lang.String |
getString(java.io.InputStream inputStream)
returns a string from an input stream |
static int |
indexOfIgnoreCase(java.lang.String sString1,
java.lang.String sString2)
Returns the index within the first string of the first occurrence of the second string regardless of case. |
static int |
indexOfIgnoreCase(java.lang.String sString1,
java.lang.String sString2,
int nStartIndex)
Returns the index within the first string of the first occurrence of the second string regardless of case, starting at the specified index. |
static boolean |
isNotEmpty(java.lang.String s)
|
static int |
isStringInStringArray(java.lang.String[] saArray,
java.lang.String sString,
boolean bCaseInsenstive)
Looks for a string in a string array |
static boolean |
isTrue(java.lang.String sKey)
Function returns true if the given string, when trimmed and lower cased, is either "yes", "1", "on" or "true". |
static java.lang.String |
javaScriptEscape(java.lang.String sToEscape)
|
static java.lang.String |
makeUniqueElement(java.lang.String[] asElements,
java.lang.String sToCheck)
Checks whether sToCheck is contained in the array asElements. |
static java.lang.String |
nullToEmpty(java.lang.String sInput)
If the input string is null, this converts it to empty, otherwise leaves it be |
static java.lang.String[] |
or(java.lang.String[] s1,
java.lang.String[] s2)
A case sensitive string array OR - returns a string array containing only one occurance of any string in s1 and s2 |
static java.lang.String |
padWithZeros(java.lang.String sNumber,
int n)
Pads a string out to length n with leading zeros |
static java.lang.String |
pluralise(java.lang.String sSingular,
java.lang.String sPlural,
int nToTest)
returns either the singular or the plural based on the value of the number For example: out.println( "This code is " + StringUtils.pluralise( "mine", "ours", nNumberOfCodeOwners ) + "!" ); |
static void |
print(java.lang.String s)
|
static java.lang.String[] |
quickSort(java.lang.String[] asToSort)
Quick sort string arrays into lexicgraphical order |
static void |
quickSort(java.util.Vector vec)
Quick sort vectors into lexicgraphical order |
static java.lang.String[] |
quickSortWithMirror(java.lang.String[] asToSort,
java.lang.String[] asToMirror)
Quick sort string arrays into lexicgraphical order, mirroring the changes in asToMirror |
static java.lang.String |
removeFormatting(java.lang.String sString)
Removes all formatting characters from a string |
static java.lang.String[] |
split(java.lang.String sInput,
java.lang.String sSplitCharacter)
Method to Split up a CSV String into an array. |
static int[] |
stringArrayToIntArray(java.lang.String[] sToIntArray)
Quick method to convert a string array to int array |
static long[] |
stringArrayToLongArray(java.lang.String[] sToLongArray)
Quick method to convert a string array to long array |
static java.util.Vector |
stringArrayToVector(java.lang.Object[] saInput)
creates a vector containing the same elements as an array |
static java.lang.String |
stringReplace(java.lang.String sInputString,
java.lang.String sToReplace,
java.lang.String sReplacementString)
Replace muliple occurrences of the specified string within an input string |
static java.lang.String |
stringReplaceIgnoreCase(java.lang.String sInputString,
java.lang.String sToReplace,
java.lang.String sReplacementString)
Replace multiple occurrences of the specified string within an input string, regardless of case |
static java.lang.String |
stripDangerousChars(java.lang.String sString)
Safety net for catching and stripping < > and ", which can be dangerous when working with dynamically generated HTML pages ( ie JSP pages or Servlets ). |
static java.lang.String |
stripHTML(java.lang.String sIn)
Strips out all HTML in the given string |
static java.lang.String |
stripNonAlphaNum(java.lang.String sString)
Removes all non-alphanumeric characters from the string |
static boolean |
strValid(java.lang.String sTest)
Returns true if the string isn't null or empty |
static boolean |
strValid(java.lang.String sTest,
int nMaxLength)
Returns true if the string isn't null and between 1 and MaxLength chars long Pass in 0 or a negative number for maxlength and it will not check for length |
static java.lang.String |
toSentenceCase(java.lang.String sInput)
Puts Strings Into This Form |
static java.lang.String |
urlDecode(java.lang.String sUrlEncoded)
Method to decode URLs, as this is not present in JRE1.1 environments |
static java.lang.String[] |
vectorToStringArray(java.util.Vector vInput)
creates a vector containing the same elements as an array |
static boolean |
wildcardStringEquals(java.lang.String sWild,
java.lang.String sComp,
boolean bCaseSensitive)
compares two strings, sWild may contain wildcards '?' & '*'. |
static java.lang.String |
XMLEscape(java.lang.String sToEscape)
Performs a basic <, >, ", &, ' XML Escape on the given string |
static java.lang.String |
XMLUnescape(java.lang.String sToEscape)
XML unescapes the given string. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringUtils()
Method Detail |
public static java.lang.String[] split(java.lang.String sInput, java.lang.String sSplitCharacter)
sInput
- Input CSV String separated by sSplitCharacter'ssSplitCharacter
- Separator characterspublic static java.lang.String combine(java.lang.String[] saInput, java.lang.String sSplitCharacter)
saInput
- Input Array of StringssSplitCharacter
- Separator characters
public static boolean isTrue(java.lang.String sKey)
public static java.lang.String ensureSeparatorAtEnd(java.lang.String sToSlash)
sToSlash
- to be checked snd possibly have slash appendedpublic static java.lang.String ensureNoSeparatorAtEnd(java.lang.String sToSlash)
sToSlash
- to be checked snd possibly have slash appendedpublic static java.lang.String getHTMLColorFromString(java.lang.String sToParse)
sToParse
- string to parse
public static java.lang.String getImageNameFromString(java.lang.String sToParse) throws java.lang.StringIndexOutOfBoundsException
sToParse
- string to parse
java.lang.StringIndexOutOfBoundsException
public static java.lang.String nullToEmpty(java.lang.String sInput)
public static boolean strValid(java.lang.String sTest, int nMaxLength)
sTest
- The string to testpublic static boolean strValid(java.lang.String sTest)
sTest
- The string to testpublic static boolean containsIllegalChars(java.lang.String sTest)
public static boolean containsNonAlphaNumericChars(java.lang.String sTest)
public static java.lang.String[] quickSort(java.lang.String[] asToSort)
asToSort
- string to sort
public static java.lang.String[] quickSortWithMirror(java.lang.String[] asToSort, java.lang.String[] asToMirror)
asToSort
- string to sort
public static void quickSort(java.util.Vector vec)
vec
- vector to sortpublic static java.lang.String[] or(java.lang.String[] s1, java.lang.String[] s2)
s1
- String 1 for ORrings2
- String 2 for ORringpublic static java.lang.String makeUniqueElement(java.lang.String[] asElements, java.lang.String sToCheck)
asElements
- Array of strings against which sToCheck should be comparedsToCheck
- The string to be checked.
public static void print(java.lang.String s)
public static java.lang.String stringReplace(java.lang.String sInputString, java.lang.String sToReplace, java.lang.String sReplacementString)
sInputString
- String to changesToReplace
- The substring to findsReplacementString
- The string to replace sToReplace with.
public static java.lang.String stringReplaceIgnoreCase(java.lang.String sInputString, java.lang.String sToReplace, java.lang.String sReplacementString)
sInputString
- String to changesToReplace
- The substring to findsReplacementString
- The string to replace sToReplace with. The case formatting of this string is conserved.
public static int indexOfIgnoreCase(java.lang.String sString1, java.lang.String sString2)
sString1
- The string to be searchsString2
- The substring to be found
public static int indexOfIgnoreCase(java.lang.String sString1, java.lang.String sString2, int nStartIndex)
sString1
- The string to be searchsString2
- The substring to be found
public static java.lang.String XMLEscape(java.lang.String sToEscape)
public static java.lang.String XMLUnescape(java.lang.String sToEscape)
public static int binarySearch(java.lang.String[] saInput, char cChar, boolean bReturnNotFound)
saInput
- The array in which to search [this must be sorted]cChar
- The string to findbReturnNotFound
- will return -1 if not found, otherwise will return the earliest element starting with the closest char after cChar
public static int binarySearch(java.util.Vector vInput, char cChar, boolean bReturnNotFound)
vInput
- The vector in which to search [this must be sorted]cChar
- The string to findbReturnNotFound
- will return -1 if not found, otherwise will return the earliest element starting with the closest char after cChar
public static int binarySearch(java.util.Vector vInput, java.lang.String sToFind, boolean bReturnNotFound)
vInput
- The vector in which to search [this must be sorted]sToFind
- The string to findbReturnNotFound
- if true will return -1 if not found, otherwise will return the earliest element starting with the closest String after sToFind
public static int[] stringArrayToIntArray(java.lang.String[] sToIntArray)
public static long[] stringArrayToLongArray(java.lang.String[] sToLongArray)
public static int isStringInStringArray(java.lang.String[] saArray, java.lang.String sString, boolean bCaseInsenstive)
saArray
- String array to parsesString
- string to findbCaseInsenstive
- case sensitivity flag
public static java.util.Vector stringArrayToVector(java.lang.Object[] saInput)
public static java.lang.String[] vectorToStringArray(java.util.Vector vInput)
public static int atoi(java.lang.String sNumber, int nDefault)
public static long atol(java.lang.String sNumber, long nDefault)
public static float atof(java.lang.String sNumber, float fDefault)
public static double atod(java.lang.String sNumber, double dDefault)
public static boolean atob(java.lang.String sKey, boolean bDefault)
public static java.lang.String stripDangerousChars(java.lang.String sString)
public static java.lang.String stripNonAlphaNum(java.lang.String sString)
public static java.lang.String toSentenceCase(java.lang.String sInput)
public static java.lang.String pluralise(java.lang.String sSingular, java.lang.String sPlural, int nToTest)
out.println( "This code is " + StringUtils.pluralise( "mine", "ours", nNumberOfCodeOwners ) + "!" );
sSingular
- singular wordsPlural
- plural of that wordnToTest
- a number
public static java.lang.String padWithZeros(java.lang.String sNumber, int n)
public static java.lang.String urlDecode(java.lang.String sUrlEncoded)
public static boolean wildcardStringEquals(java.lang.String sWild, java.lang.String sComp, boolean bCaseSensitive)
sWild
- first String to compare. May contain wildcardssComp
- second String to compare.bCaseSensitive
- case sensitive or not
public static java.lang.String encryptString(java.lang.String sToEncrypt)
sToEncrypt
- the string to encrypt
public static java.lang.String decryptString(java.lang.String sToDecrypt)
sToDecrypt
- the string to decrypt
public static java.lang.String getString(java.io.InputStream inputStream)
inputStream
- InputStream
public static java.lang.String removeFormatting(java.lang.String sString)
sString
- the string to clean
public static java.util.Enumeration deduplicate(java.lang.String[] as)
public static java.lang.String stripHTML(java.lang.String sIn)
sIn
- string to strip HTML from
public static java.lang.String javaScriptEscape(java.lang.String sToEscape)
public static boolean isNotEmpty(java.lang.String s)
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |