com.amx.duet.tools.text
Class StringUtil

java.lang.Object
  extended bycom.amx.duet.tools.text.StringUtil

public class StringUtil
extends java.lang.Object

A utility class, which contains a variety of String manipulation routines.

Version:
1.0.0

Constructor Summary
StringUtil()
           
 
Method Summary
static int FindString(java.lang.String str, java.lang.String pattern, int start)
          Searches through a string for a specified sequence of characters.
static char GetBufferChar(ObjectRef rbuffer)
          This function is used to remove characters from a buffer.
static java.lang.String GetBufferString(ObjectRef rbuffer, int count)
          This function is used to remove characters from a buffer.
static java.lang.String LeftString(java.lang.String str, int count)
          Retrieves a String containing the specified number of characters from the beginning of a string.
static java.lang.String MidString(java.lang.String str, int start, int count)
          Retrieves a String containing the specified number of characters starting at the specified location in the source string.
static java.lang.String[] parse(java.lang.String data, java.lang.String delim)
          Returns an array of strings containing each parsed value
static java.lang.String RemoveString(ObjectRef rStr, int count)
          This function is used to remove a number of characters from a string
static java.lang.String RemoveString(ObjectRef rStr, java.lang.String pattern)
          Removes the first instance of the passed in pattern from the source string and manipulates the source string parameter to reflect the changes.
static java.lang.String RemoveString(ObjectRef rStr, java.lang.String pattern, int start)
          Removes the first instance of the passed in pattern from the source string starting from the offset value and manipulates the source string parameter to reflect the changes.
static java.lang.String RemoveString(java.lang.String str, int count)
          This function is used to remove a number of characters from a string
static java.lang.String RemoveString(java.lang.String str, java.lang.String pattern)
          Removes the first instance of the passed in pattern from the source string but does not change the source string in anyway.
static java.lang.String RemoveString(java.lang.String str, java.lang.String pattern, int start)
          Removes the first instance of the passed in pattern from the source string starting from the offset value but does not change the source string in anyway.
static java.lang.String RemoveStringAll(java.lang.String str, java.lang.String pattern)
          Removes every instance of the passed in pattern from the string and returns the new string without any of the pattern data.
static java.lang.String ReplaceString(java.lang.String str, java.lang.String pattern, java.lang.String replace)
          Removes every instance of the passed in pattern from the string and replaces them with the replace pattern.
static java.lang.String RightString(java.lang.String str, int count)
          Retrieves a String containing the specified number of characters from the end of a string.
static java.lang.String toAsciiHexString(byte[] bArr)
          Generates an ASCII hex string from the byte array passed in.
static byte[] writeBytes(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this byte array (Code that I just didn't want to throw away, but is already being done in other places.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

parse

public static final java.lang.String[] parse(java.lang.String data,
                                             java.lang.String delim)
Returns an array of strings containing each parsed value

Parameters:
data - data string to be parsed
delim - string delimiter to parse the data by
Returns:
an array of strings

ReplaceString

public static final java.lang.String ReplaceString(java.lang.String str,
                                                   java.lang.String pattern,
                                                   java.lang.String replace)
Removes every instance of the passed in pattern from the string and replaces them with the replace pattern.

Parameters:
str - String to be manipulated
pattern - Pattern to remove from source string
replace - Pattern to replace removed pattern with
Returns:
the newly replaced string

RemoveStringAll

public static final java.lang.String RemoveStringAll(java.lang.String str,
                                                     java.lang.String pattern)
Removes every instance of the passed in pattern from the string and returns the new string without any of the pattern data.

Parameters:
str - String to be manipulated
pattern - Pattern to remove from source string
Returns:
String that no longer contains pattern

RemoveString

public static final java.lang.String RemoveString(java.lang.String str,
                                                  java.lang.String pattern)
Removes the first instance of the passed in pattern from the source string but does not change the source string in anyway.

Parameters:
str - Source string to be manipulated
pattern - Pattern to remove from source string
Returns:
String that no longer contains pattern

RemoveString

public static final java.lang.String RemoveString(ObjectRef rStr,
                                                  java.lang.String pattern)
Removes the first instance of the passed in pattern from the source string and manipulates the source string parameter to reflect the changes.

Parameters:
rStr - Must be of type String. ObjectRef containing the source string data to be manipulated (value is passed by reference).

Create rStr with a valueOf(String) Example:
ObjectRef rStr = new ObjectRef("") or rStr.valueOf("")

pattern - Pattern to remove from source string
Returns:
String that no longer contains pattern

RemoveString

public static final java.lang.String RemoveString(java.lang.String str,
                                                  java.lang.String pattern,
                                                  int start)
Removes the first instance of the passed in pattern from the source string starting from the offset value but does not change the source string in anyway.

Parameters:
str - Source string to be manipulated
pattern - Pattern to remove from source string
start - offset value
Returns:
String that no longer contains pattern

RemoveString

public static final java.lang.String RemoveString(ObjectRef rStr,
                                                  java.lang.String pattern,
                                                  int start)
Removes the first instance of the passed in pattern from the source string starting from the offset value and manipulates the source string parameter to reflect the changes.

Parameters:
rStr - Must be of type String. ObjectRef containing the source string data to be manipulated (value is passed by reference).

Create rStr with a valueOf(String) Example:
ObjectRef rStr = new ObjectRef("") or rStr.valueOf("")

pattern - Pattern to remove from source string
start - offset value
Returns:
String that no longer contains pattern

RemoveString

public static final java.lang.String RemoveString(ObjectRef rStr,
                                                  int count)
This function is used to remove a number of characters from a string

Parameters:
rStr - Must be of type String. ObjectRef containing the source string data to be manipulated (value is passed by reference).

Create rStr with a valueOf(String) Example:
ObjectRef rStr = new ObjectRef("") or rStr.valueOf("")

count - the number of characters to remove
Returns:
String that contains all of the characters that were removed from the string

RemoveString

public static final java.lang.String RemoveString(java.lang.String str,
                                                  int count)
This function is used to remove a number of characters from a string

Parameters:
str - Source string to be manipulated
count - the number of characters to remove
Returns:
Only the character that were not removed from the string

writeBytes

public static final byte[] writeBytes(byte[] b,
                                      int off,
                                      int len)
Writes len bytes from the specified byte array starting at offset off to this byte array (Code that I just didn't want to throw away, but is already being done in other places. Acts like a mid string or sub string method.)

Parameters:
b - source byte array containing all of the data
off - offset value to start copying source array from
len - number of bytes to copy after offset
Returns:
new byte array containg the copied bytes

toAsciiHexString

public static final java.lang.String toAsciiHexString(byte[] bArr)
Generates an ASCII hex string from the byte array passed in. ex. {0x1a, 0x1b, 0x1c} returns "1A1B1C"

Returns:
ASCII hex representation of a byte array

GetBufferString

public static final java.lang.String GetBufferString(ObjectRef rbuffer,
                                                     int count)
This function is used to remove characters from a buffer. GetBufferString() has a two-part operation:

1. Retrieve the characters from the buffer up to the specified count.
2. Remove the retrieved characters from the buffer and shift the remaining characters up to fill the gap.

Parameters:
count - the number of characters to be retrieved and then shifted
Returns:
String that contains all of the characters that were removed from the string

GetBufferChar

public static final char GetBufferChar(ObjectRef rbuffer)
This function is used to remove characters from a buffer. GetBufferChar() has a two-part operation:

1. Retrieve the first character in the buffer.
2. Remove the retrieved character from the buffer and shift the remaining characters by one to fill the gap.

Returns:
The character that was removed from the string.

LeftString

public static final java.lang.String LeftString(java.lang.String str,
                                                int count)
Retrieves a String containing the specified number of characters from the beginning of a string.

Parameters:
str - the string from which to extract the characters.
count - the number of character to copy from the beginning of the string.
Returns:
A String containing a copy of the first count characters from the string.

RightString

public static final java.lang.String RightString(java.lang.String str,
                                                 int count)
Retrieves a String containing the specified number of characters from the end of a string.

Parameters:
str - the string from which to extract the characters.
count - the number of character to copy from the end of the string.
Returns:
A String containing a copy of the last count characters from the string.

MidString

public static final java.lang.String MidString(java.lang.String str,
                                               int start,
                                               int count)
Retrieves a String containing the specified number of characters starting at the specified location in the source string.

Parameters:
str - the string from which to extract the characters.
start - the starting location in the string.
count - the number of characters to extract.
Returns:
A String containing a copy of the specified characters from the string.

FindString

public static final int FindString(java.lang.String str,
                                   java.lang.String pattern,
                                   int start)
Searches through a string for a specified sequence of characters.

Parameters:
str - the string of characters to search.
pattern - the sequence of characters to search for
start - the starting character position for the search
Returns:
An integer representing the character location of pattern in the string. If the character sequence is found at the beginning of the string, this method returns 0. Any error condition returns -1.


Copyright © 2008 AMX LLC. All Rights Reserved.