Diamond Control Suite 3.0

diamondedge.util
Class Strings

java.lang.Object
  extended by diamondedge.util.Strings

public class Strings
extends Object


Constructor Summary
Strings()
           
 
Method Summary
static int asc(String str)
          returns the ascii code corresponding to the first letter in a string
static String clean(String str)
          Removes all control characters from the string.
static int compare(String str1, String str2)
          returns a value indicating the result of a string comparison
static String fill(int num, char c)
          Returns a String containing a repeating character of the length specified
static String fill(int num, String c)
          Returns a String containing a repeating character (first char of string) of the length specified
static int find(int start, String str, String substr)
          Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str index that is returned is 1-based
static int find(int start, String str, String substr, boolean ignoreCase)
          Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str index that is returned is 1-based
static int find(String str, String substr)
          Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str
static int findReverse(String str, String substr, int start, boolean ignoreCase)
          Returns the 1-based index of the last occurrence of one string within another
static String format(double num, String format)
           Named Numeric Formats --------------------- General Number Display number with no thousand separator.
static String format(String expr, String format)
          Returns the string expression formated according to the given format
static String format(Variant expr, String format)
           
static String formatCurrency(double expr, int NumDigitsAfterDecimal, boolean IncludeLeadingDigit, boolean UseParensForNegativeNumbers, boolean GroupDigits)
          Formats expression as currency
static String formatNumber(double expr, int NumDigitsAfterDecimal, boolean IncludeLeadingDigit, boolean UseParensForNegativeNumbers, boolean GroupDigits)
          Formats expression as number
static String formatPercent(double expr, int NumDigitsAfterDecimal, boolean IncludeLeadingDigit, boolean UseParensForNegativeNumbers, boolean GroupDigits)
          Formats expression as percent
static boolean isNull(String str)
           
static String join(Object[] arr, String delimiter)
          Join array elements into a string
static String join(Variant arr, String delimiter)
          Join array elements into a string
static String left(String str, int length)
          returns a specified number of characters from the left side of a string
static int len(String str)
          returns the number of characters in a string
static String mid(String str, int start)
          returns the remaining characters from a string
static String mid(String str, int start, int length)
          returns a specified number of characters from a string
static String mid(String str, int start, int maxlength, String replaceWithStr)
          replaces up to a specified number of characters with the given string.
static String repeat(String str, int num)
          Returns a string repeated a specified number of times.
static String replace(String str, String replaceStr, String withStr)
          Find and replace all occurrences of a substring within a string.
static String replace(String str, String replaceStr, String withStr, int start, int count)
          Finds and replaces the first occurrences of a substring within a string.
static String replaceMid(String str, int start, int length, String withStr)
          replaces the specified number of characters with the given string
static String replaceOccurrence(String str, String replaceStr, String withStr, int occurrenceNumber)
          Finds and replaces one particular occurrence of a substring within a string
static String right(String str, int length)
          returns a specified number of characters from the right side of a string
static String space(int num)
          Returns a String containing a repeating ' '(space) of the length specified
static String[] split(String str, String delimiter, int count)
          Split a string into an array.
static String toLowerCase(String str)
          returns a string that has been converted to lowercase
static String toProperCase(String str)
          returns a string that has been converted to uppercase
static String toUpperCase(String str)
          returns a string that has been converted to uppercase
static String trim(String str)
          Removes all spaces at the beginning and end of the string
static String trimAll(String str)
          Removes all spaces at the beginning and end of the string as well as multiple spaces in between words are replace with a single space.
static String trimLeft(String str)
          Removes all spaces at the beginning of the string
static String trimRight(String str)
          Removes all spaces at the end of the string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

isNull

public static boolean isNull(String str)

asc

public static int asc(String str)
returns the ascii code corresponding to the first letter in a string


mid

public static String mid(String str,
                         int start,
                         int length)
returns a specified number of characters from a string


mid

public static String mid(String str,
                         int start)
returns the remaining characters from a string


mid

public static String mid(String str,
                         int start,
                         int maxlength,
                         String replaceWithStr)
replaces up to a specified number of characters with the given string. The number of characters replaced is the minimum of maxlength and the length of replaceWithStr.

Parameters:
str - String to be modified
start - 1-based position in str to begin replacing
maxlength - maximum number of characters to replace
replaceWithStr - new string to replace the given characters with

replaceMid

public static String replaceMid(String str,
                                int start,
                                int length,
                                String withStr)
replaces the specified number of characters with the given string

Parameters:
str - String to be modified
start - 1-based position in str to begin replacing
length - number of characters to be removed
withStr - new string to replace the removed characters with

replace

public static String replace(String str,
                             String replaceStr,
                             String withStr)
Find and replace all occurrences of a substring within a string.

Parameters:
str - String to be modified
replaceStr - substring to find
withStr - new string to replace the substring with

replace

public static String replace(String str,
                             String replaceStr,
                             String withStr,
                             int start,
                             int count)
Finds and replaces the first occurrences of a substring within a string.

Parameters:
str - String to be modified
replaceStr - substring to find
withStr - new string to replace the substring with
start - 1-based position in str to begin replacing
count - number of occurrences to replace

replaceOccurrence

public static String replaceOccurrence(String str,
                                       String replaceStr,
                                       String withStr,
                                       int occurrenceNumber)
Finds and replaces one particular occurrence of a substring within a string

Parameters:
str - String to be modified
replaceStr - substring to find
withStr - new string to replace the substring with
occurrenceNumber - occurrence of substring to replace

left

public static String left(String str,
                          int length)
returns a specified number of characters from the left side of a string


right

public static String right(String str,
                           int length)
returns a specified number of characters from the right side of a string


toLowerCase

public static String toLowerCase(String str)
returns a string that has been converted to lowercase


toUpperCase

public static String toUpperCase(String str)
returns a string that has been converted to uppercase


toProperCase

public static String toProperCase(String str)
returns a string that has been converted to uppercase


trimLeft

public static String trimLeft(String str)
Removes all spaces at the beginning of the string


trimRight

public static String trimRight(String str)
Removes all spaces at the end of the string


trim

public static String trim(String str)
Removes all spaces at the beginning and end of the string


trimAll

public static String trimAll(String str)
Removes all spaces at the beginning and end of the string as well as multiple spaces in between words are replace with a single space. Note: trimming multiple spaces in between words requires Java v1.4


clean

public static String clean(String str)
Removes all control characters from the string.


len

public static int len(String str)
returns the number of characters in a string


find

public static int find(int start,
                       String str,
                       String substr,
                       boolean ignoreCase)
Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str index that is returned is 1-based

Parameters:
start - 1-based position to start search
str - String to be search
substr - String to find inside str
ignoreCase - true if should perform a case insensitive search

find

public static int find(int start,
                       String str,
                       String substr)
Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str index that is returned is 1-based

Parameters:
start - 1-based position to start search
str - String to be search
substr - String to find inside str

find

public static int find(String str,
                       String substr)
Returns the 1-based index of substr in str otherwise returns 0 if substr is not found in str


findReverse

public static int findReverse(String str,
                              String substr,
                              int start,
                              boolean ignoreCase)
Returns the 1-based index of the last occurrence of one string within another


compare

public static int compare(String str1,
                          String str2)
returns a value indicating the result of a string comparison


space

public static String space(int num)
Returns a String containing a repeating ' '(space) of the length specified


fill

public static String fill(int num,
                          char c)
Returns a String containing a repeating character of the length specified


fill

public static String fill(int num,
                          String c)
Returns a String containing a repeating character (first char of string) of the length specified


repeat

public static String repeat(String str,
                            int num)
Returns a string repeated a specified number of times.


formatNumber

public static String formatNumber(double expr,
                                  int NumDigitsAfterDecimal,
                                  boolean IncludeLeadingDigit,
                                  boolean UseParensForNegativeNumbers,
                                  boolean GroupDigits)
Formats expression as number


formatPercent

public static String formatPercent(double expr,
                                   int NumDigitsAfterDecimal,
                                   boolean IncludeLeadingDigit,
                                   boolean UseParensForNegativeNumbers,
                                   boolean GroupDigits)
Formats expression as percent


formatCurrency

public static String formatCurrency(double expr,
                                    int NumDigitsAfterDecimal,
                                    boolean IncludeLeadingDigit,
                                    boolean UseParensForNegativeNumbers,
                                    boolean GroupDigits)
Formats expression as currency


join

public static String join(Object[] arr,
                          String delimiter)
Join array elements into a string


join

public static String join(Variant arr,
                          String delimiter)
Join array elements into a string


split

public static String[] split(String str,
                             String delimiter,
                             int count)
Split a string into an array. If count < 0 then all strings are returned in separate elements. If count > 0 then the string will be split into 1 to count number of elements depending on how many delimiters there are. The last element may contain delimiters.


format

public static String format(double num,
                            String format)
Named Numeric Formats
---------------------
General Number  Display number with no thousand separator.
Currency        Display number with thousand separator, if appropriate; display two digits to the right of the decimal separator. Output is based on systemlocale settings.
Fixed           Display at least one digit to the left and two digits to the right of the decimal separator.
Standard        Display number with thousand separator, at least one digit to the left and two digits to the right of the decimal separator.
Percent         Display number multiplied by 100 with a percent sign (%) appended to the right; always display two digits to the right of the decimal separator.
Scientific      Use standard scientific notation.
Yes/No          Display No if number is 0; otherwise, display Yes.
True/False      Display False if number is 0; otherwise, display True.
On/Off          Display Off if number is 0; otherwise, display On.

User-defined Numeric Formats
----------------------------
None            Display the number with no formatting.
0               Digit placeholder. Display a digit or a zero. If the expression has a digit in the position where the 0 appears in the format string, display it; otherwise, display a zero in that position. If the number has fewer digits than there are zeros (on either side of the decimal) in the format expression, display leading or trailing zeros. If the number has more digits to the right of the decimal separator than there are zeros to the right of the decimal separator in the format expression, round the number to as many decimal places as there are zeros. If the number has more digits to the left of the decimal separator than there are zeros to the left of the decimal separator in the format expression, display the extra digits without modification.
#               Digit placeholder. Display a digit or nothing. If the expression has a digit in the position where the # appears in the format string, display it; otherwise, display nothing in that position. This symbol works like the 0 digit placeholder, except that leading and trailing zeros aren't displayed if the number has the same or fewer digits than there are # characters on either side of the decimal separator in the format expression.
.               Decimal placeholder. In somelocales, a comma is used as the decimal separator. The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. To display a leading zero displayed with fractional numbers, use 0 as the first digit placeholder to the left of the decimal separator. The actual character used as a decimal placeholder in the formatted output depends on the Number Format recognized by your system.
%               Percentage placeholder. The expression is multiplied by 100. The percent character (%) is inserted in the position where it appears in the format string.
,               Thousand separator. In some locales, a period is used as a thousand separator. The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. Standard use of the thousand separator is specified if the format contains a thousand separator surrounded by digit placeholders (0 or #). Two adjacent thousand separators or a thousand separator immediately to the left of the decimal separator (whether or not a decimal is specified) means "scale the number by dividing it by 1000, rounding as needed." For example, you can use the format string "##0,," to represent 100 million as 100. Numbers smaller than 1 million are displayed as 0. Two adjacent thousand separators in any position other than immediately to the left of the decimal separator are treated simply as specifying the use of a thousand separator. The actual character used as the thousand separator in the formatted output depends on the Number Format recognized by your system.
:               Time separator. In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings.
/               Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.
E- E+ e- e+     Scientific format. If the format expression contains at least one digit placeholder (0 or #) to the right of E-, E+, e-, or e+, the number is displayed in scientific format and E or e is inserted between the number and its exponent. The number of digit placeholders to the right determines the number of digits in the exponent. Use E- or e- to place a minus sign next to negative exponents. Use E+ or e+ to place a minus sign next to negative exponents and a plus sign next to positive exponents.
- + $ ( )       Display a literal character. To display a character other than one of those listed, precede it with a backslash (\) or enclose it in double quotation marks (" ").
\               Display the next character in the format string. To display a character that has special meaning as a literal character, precede it with a backslash (\). The backslash itself isn't displayed. Using a backslash is the same as enclosing the next character in double quotation marks. To display a backslash, use two backslashes (\\). Examples of characters that can't be displayed as literal characters are the date-formatting and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, / and :), the numeric-formatting characters (#, 0, %, E, e, comma, and period), and the string-formatting characters (@, &, <, >, and !).
"ABC"           Display the string inside the double quotation marks (" "). To include a string in format from within code, you must use Chr(34) to enclose the text (34 is thecharacter code for a quotation mark (")).

Different Formats for Different Numeric Values (Format Function)
----------------------------------------------------------------
A user-defined format expression for numbers can have from one or two sections separated by semicolons. If the format argument contains one of the named numeric formats, only one section is allowed.

If you use The result is
One section only The format expression applies to all values.
Two sections The first section applies to positive values and zeros, the second to negative values.

The following example has two sections: the first defines the format for positive values and zeros; the second section defines the format for negative values.

"$#,##0;($#,##0)"


format

public static String format(String expr,
                            String format)
Returns the string expression formated according to the given format

Parameters:
expr - string expression to format
format - the format which consists of the following placeholders:
  @ Character placeholder. Display a character or a space. If the string has a character in the position where the at symbol (@) appears in the format string, display it; otherwise, display a space in that position. Placeholders are filled from right to left unless there is an exclamation point character (!) in the format string.
  & Character placeholder. Display a character or nothing. If the string has a character in the position where the ampersand (&) appears, display it; otherwise, display nothing. Placeholders are filled from right to left unless there is an exclamation point character (!) in the format string.
  < Force lowercase. Display all characters in lowercase format.
  > Force uppercase. Display all characters in uppercase format.
  ! Force left to right fill of placeholders. The default is to fill placeholders from right to left.
 

format

public static String format(Variant expr,
                            String format)

Diamond Control Suite 3.0

Diamond Edge and Diamond Control Suite are trademarks or registered trademarks of Diamond Edge, Inc. Copyright 1999-2005 Diamond Edge, Inc. All Rights Reserved.