com.objectwave.utility
Class StringManipulator

java.lang.Object
  |
  +--com.objectwave.utility.StringManipulator

public class StringManipulator
extends java.lang.Object

StringManipulator contains functions that assist with String manipulation. As the language evolves many of these functions will likely become obsolete. An actual supported JDK version of any of these functions should be used instead of using this class.

Version:
2.2

Nested Class Summary
static class StringManipulator.Test
          Using an inner class for a test case accomplishes at least two things.
 
Constructor Summary
StringManipulator()
           
 
Method Summary
static java.lang.String convertFromASCII(java.lang.String str)
          Decode from printable ASCII: all characters < 32 and > 127 were encoded using '#' as the escape character.
static java.lang.String convertToASCII(java.lang.String str)
          Encode to printable ASCII: all characters < 32 and > 127 are encoded using '#' as the escape character.
static java.lang.String convertToASCII(java.lang.String str, java.lang.String alsoEscape)
           
static double doubleValue(java.lang.String aString)
          Return the string as a double.
static java.util.Vector extractStringsDelimiter(java.lang.String source, int ch)
          Break a string out into a vector, using the parameter 'ch' as a delimeter.
static java.util.Vector extractStringsDelimiter(java.lang.String source, java.lang.String ch)
           
static float floatValue(java.lang.String aString)
          Return the string as a float.
static java.util.Date getDateForString(java.lang.String str)
           
static int integerValue(java.lang.String aString)
          Return the string as an integer.
static boolean isPatternMatch(java.lang.String pattern, java.lang.String target)
          Allow the use of '*' in defining patterns.
static boolean isPatternMatch(java.lang.String pattern, java.lang.String target, char wildChar)
          Allow the use of a wildChar in defining patterns.
static void main(java.lang.String[] args)
           
static boolean matchesPattern(java.lang.String str, java.lang.String pattern)
          Check to see if the string str matches the given pattern.
static boolean matchesPattern(java.lang.String str, java.lang.String pattern, char wildStr, char wildChar)
          Determine if the string matches the pattern provided.
static java.lang.String nextValuePair(java.lang.String source, java.lang.String pair, int start)
           
static java.lang.String nextValuePair(java.lang.String source, java.lang.String pair, int start, boolean special)
           
static java.lang.String oneLine(java.lang.String source)
          Return the source as 1 line of code.
static java.lang.String[] parsePhoneNumber(java.lang.String phoneNumber)
           
static java.lang.String reduceString(java.lang.String str, int maxNum)
          Try to reduce the given string intelligently to fit the given number of characters.
static java.lang.String replaceAllWith(java.lang.String source, java.lang.String from, java.lang.String to)
          With the 'source' string, replace all occurances of 'from' with 'to'.
static java.lang.String replaceStringWith(java.lang.String source, java.lang.String from, java.lang.String to)
          With the 'source' string, replace the first occurance of 'from' with 'to'.
static java.lang.String resolveToCharacters(java.lang.String source)
          Replace all instances of %## (like %20) with their actual character representation.
static java.util.Vector stringToVector(java.lang.String s)
           
static java.util.Vector stringToVector(java.lang.String s, char escape, char delimiter)
          Convert a delimited string to a vector of strings.
static java.util.Vector stringToVector(java.lang.String s, char escape, char delimiter, boolean ignoreEmptyElements)
          Convert a delimited string to a vector of strings.
static java.lang.String toNumber(java.lang.String aString)
          This will pull out the first number found in the string parameter.
static java.lang.String trimLeadingBlanks(java.lang.String source)
          The method name says it all.
static java.lang.String vectorToString(java.util.Vector v)
           
static java.lang.String vectorToString(java.util.Vector v, char escape, char delimiter)
          Convert a vector to a delimited string (using vector elements' toString()).
static java.lang.String xorCrypto(java.lang.String source, java.lang.String password)
          This is a rude & crude implementation of the simplest cryptographic algorithm known to man.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringManipulator

public StringManipulator()
Method Detail

convertFromASCII

public static java.lang.String convertFromASCII(java.lang.String str)
Decode from printable ASCII: all characters < 32 and > 127 were encoded using '#' as the escape character. '#' was encoded to '##'. The given char c was encoded to two hex digits preceeded by a '#'.

Parameters:
str - The string being operated upon.

convertToASCII

public static java.lang.String convertToASCII(java.lang.String str)
Encode to printable ASCII: all characters < 32 and > 127 are encoded using '#' as the escape character. '#' is encoded to '##'. The given char c is encoded to two hex digits preceeded by a '#'. We assume that the original char is < 256. Perhaps later the full range of char will be supported.

Parameters:
str - The string being operated upon.

convertToASCII

public static java.lang.String convertToASCII(java.lang.String str,
                                              java.lang.String alsoEscape)
Parameters:
str - The string being operated upon.
alsoEscape -

doubleValue

public static double doubleValue(java.lang.String aString)
Return the string as a double. No exceptions allowed. If a NumberFormatException was to occur, return 0.

Parameters:
aString - The string being operated upon.

extractStringsDelimiter

public static java.util.Vector extractStringsDelimiter(java.lang.String source,
                                                       int ch)
Break a string out into a vector, using the parameter 'ch' as a delimeter. This method is operates differently than the method that takes a string as the delimeter. Quotes (") and ticks (') are considered. If a delimiter is within a String or a Character literal, that delimeter is ignored.

Parameters:
source - The string being operated upon.
ch - The character to use as a delimeter
Returns:
Vector of the elements.

extractStringsDelimiter

public static java.util.Vector extractStringsDelimiter(java.lang.String source,
                                                       java.lang.String ch)
Parameters:
source - The string being operated upon.
ch -

floatValue

public static float floatValue(java.lang.String aString)
Return the string as a float. No exceptions allowed. If a NumberFormatException was to occur, return 0.

Parameters:
aString - The string being operated upon.

getDateForString

public static java.util.Date getDateForString(java.lang.String str)
Parameters:
str - The string being operated upon.

integerValue

public static int integerValue(java.lang.String aString)
Return the string as an integer. No exceptions allowed. If a NumberFormatException was to occur, return 0.

Parameters:
aString - The string being operated upon.

isPatternMatch

public static boolean isPatternMatch(java.lang.String pattern,
                                     java.lang.String target)
Allow the use of '*' in defining patterns. Similar to indexOf.

Parameters:
pattern -
target - The string being operated upon.

isPatternMatch

public static boolean isPatternMatch(java.lang.String pattern,
                                     java.lang.String target,
                                     char wildChar)
Allow the use of a wildChar in defining patterns. Similar to indexOf. Note: matchesPattern() is a more powerful implementation of this. This method now calls matchesPattern().

Parameters:
pattern -
target - The string being operated upon.
wildChar -

main

public static void main(java.lang.String[] args)

matchesPattern

public static boolean matchesPattern(java.lang.String str,
                                     java.lang.String pattern)
Check to see if the string str matches the given pattern. The pattern is a string conforming to SQL's LIKE pattern standard: The % character represents 0 or more characters, while _ matches exactly one character. This is a very primitive recognition scheme: there can be only one '%' in pattern, and the '%' and '_' characters cannot be escaped in the pattern.

Parameters:
str - java.lang.String The string being operated upon.
pattern - java.lang.String
Returns:
true if and only if str matches the pattern.

matchesPattern

public static boolean matchesPattern(java.lang.String str,
                                     java.lang.String pattern,
                                     char wildStr,
                                     char wildChar)
Determine if the string matches the pattern provided.

Parameters:
str - java.lang.String The string being operated upon.
pattern - java.lang.String
wildStr - char, the character which matches 0 or more characters.
wildChar - char (ex, '_' or '?'), the character which will match any one character
Returns:
boolean

nextValuePair

public static java.lang.String nextValuePair(java.lang.String source,
                                             java.lang.String pair,
                                             int start)
Parameters:
source - The string being operated upon.
pair -
start -

nextValuePair

public static java.lang.String nextValuePair(java.lang.String source,
                                             java.lang.String pair,
                                             int start,
                                             boolean special)
Parameters:
source - The string being operated upon.
pair -
start -

oneLine

public static java.lang.String oneLine(java.lang.String source)
Return the source as 1 line of code.

Parameters:
source - The string being operated upon.

parsePhoneNumber

public static java.lang.String[] parsePhoneNumber(java.lang.String phoneNumber)

reduceString

public static java.lang.String reduceString(java.lang.String str,
                                            int maxNum)
Try to reduce the given string intelligently to fit the given number of characters.

Parameters:
str - The string being operated upon.
maxNum -

replaceAllWith

public static java.lang.String replaceAllWith(java.lang.String source,
                                              java.lang.String from,
                                              java.lang.String to)
With the 'source' string, replace all occurances of 'from' with 'to'.

Parameters:
source - The string being operated upon.
from -
to -

replaceStringWith

public static java.lang.String replaceStringWith(java.lang.String source,
                                                 java.lang.String from,
                                                 java.lang.String to)
With the 'source' string, replace the first occurance of 'from' with 'to'.

Parameters:
source - The string being operated upon.
from -
to -

stringToVector

public static java.util.Vector stringToVector(java.lang.String s)

stringToVector

public static java.util.Vector stringToVector(java.lang.String s,
                                              char escape,
                                              char delimiter)
Convert a delimited string to a vector of strings.


stringToVector

public static java.util.Vector stringToVector(java.lang.String s,
                                              char escape,
                                              char delimiter,
                                              boolean ignoreEmptyElements)
Convert a delimited string to a vector of strings.


toNumber

public static java.lang.String toNumber(java.lang.String aString)
This will pull out the first number found in the string parameter.

Parameters:
aString - The string being operated upon.

trimLeadingBlanks

public static java.lang.String trimLeadingBlanks(java.lang.String source)
The method name says it all.

Parameters:
source - The string being operated upon.

vectorToString

public static java.lang.String vectorToString(java.util.Vector v)

vectorToString

public static java.lang.String vectorToString(java.util.Vector v,
                                              char escape,
                                              char delimiter)
Convert a vector to a delimited string (using vector elements' toString()).


xorCrypto

public static java.lang.String xorCrypto(java.lang.String source,
                                         java.lang.String password)
This is a rude & crude implementation of the simplest cryptographic algorithm known to man. This encryption is sufficient to protect data from a casual observer or someone with no cryptography skills or tools whatsoever, but can be cracked by anyone who really wants to.

Parameters:
source - java.lang.String The string to encrypt/decrypt
password - java.lang.String The password to use.
Returns:
java.lang.String The encrypted/decrypted text.

resolveToCharacters

public static java.lang.String resolveToCharacters(java.lang.String source)
Replace all instances of %## (like %20) with their actual character representation. All number values MUST be two digits. %02 is valid, %2 is not. Example: "A%20test" would be "A test"

Parameters:
source - java.lang.String The source string