net.nitus.widgets
Class Strings

java.lang.Object
  extended by net.nitus.widgets.Strings

public class Strings
extends java.lang.Object

Strings Creat per: Francesc Roses Modificat per: Xavier Navarro El dia 19-jul-04 a les 17:36:20 Projecte: Llibreries; Paquet: net.nitus.widgets 19/07/2004.- Funci� Strip. En lloc de fer servir un for, he fet servir un while. 19/07/2004.- Funci� primeraMaj�scula. The StringTools class contains several useful String functions from Rexx. These functions are available from NetRexx (by Mike Cowlishaw as well as Rexx) too. Rexx and NetRexx are very interesting languages. In NetRexx, these string functions apply to Rexx strings not to java.lang.String s. Frequently I need this useful functions to handle java.lang.Strings. If I convert my strings to Rexx strings, I apply the function and I convert the resulting Rexx string to java.lang.String I'll leave to use Rexx functions at second attempt. So, I decided to code most of this functions from scratch as static functions.

10/09/01: Strip returns an empty String ("") instead of null if the result string is empty. Creation date: (18/8/99 10:18:23)

Modified

11/06/99 copies(char, int)
if (times == 0) return null becomes [...] return "" like in Rexx.
11/06/99 copies(String, int)
Added if (times == 0) return "" to do the same as in copies(char, int).
11/06/99 right(String, int, char)
Added if (len = s.length()) return s.
10/04/04
Revised javadoc.

Author:
Francesc Ros�s (www.froses.com)

Constructor Summary
Strings()
           
 
Method Summary
static java.lang.String center(java.lang.String s, int len)
          center(String,int) Returns a string of length len with s centered in it, with pad characters added as necessary to make up len.
static java.lang.String center(java.lang.String s, int len, char pad)
          center(String,int,char) Returns a string of length len with s centered in it, with pad characters added as necessary to make up len.
static java.lang.String centre(java.lang.String s, int len)
          Returns a string of length len with s centered in it, with pad characters added as necessary to make up len.
static java.lang.String centre(java.lang.String s, int len, char pad)
          Returns a string of length len with s centered in it, with pad characters added as necessary to make up len.
static java.lang.String changeStr(java.lang.String needle, java.lang.String haystack, java.lang.String newneedle)
          changeStr(String, String, String) Replaces all occurrences of needle in haystack with newneedle.
static int compare(java.lang.String s1, java.lang.String s2)
          Returns -1 if the strings, string1 and string2, are identical.
static int compare(java.lang.String s1, java.lang.String s2, char pad)
          Returns -1 if the strings, string1 and string2, are identical.
static java.lang.String copies(char c, int times)
          Autor: Francesc Ros�s Albiol Returns times concatenated copies of c.
static java.lang.String copies(java.lang.String s, int times)
          Autor: Francesc Ros�s Albiol Returns times concatenated copies of c.
static int countStr(java.lang.String needle, java.lang.String haystack)
          Returns a count of the occurrences of needle in haystack that do not overlap.
static boolean dataType(java.lang.String value, char type)
          Checks if the string complies the type specification.
static java.lang.String delStr(java.lang.String s, int start)
          Returns string after deleting the substring that begins at the nth character to the end (including the nth character).
static java.lang.String delStr(java.lang.String s, int start, int len)
          Returns string after deleting the substring that begins at the nth character and is of length characters.
static java.lang.String delWord(java.lang.String s, int start)
          Returns string after deleting the substring that starts at the startth word.
static java.lang.String delWord(java.lang.String s, int start, int len)
          Returns string after deleting the substring that starts at the startth word and is of len blank-delimited words.
static java.lang.String insert(java.lang.String snew, java.lang.String target)
          Inserts the string new into the string target.
static java.lang.String insert(java.lang.String snew, java.lang.String target, int n)
          Inserts the string new into the string target after the nth character.
static java.lang.String insert(java.lang.String snew, java.lang.String target, int n, int len)
          Inserts the string new, padded or truncated to length len, into the string target after the nth character.
static java.lang.String insert(java.lang.String snew, java.lang.String target, int n, int len, char pad)
          Inserts the string new, padded or truncated to length len, into the string target after the nth character.
static int lastPos(char needle, java.lang.String haystack)
          Calls the lastIndex method of String class.
static int lastPos(char needle, java.lang.String haystack, int start)
          Calls the lastIndex method of String class.
static int lastPos(java.lang.String needle, java.lang.String haystack)
          Calls the lastIndex method of String class.
static int lastPos(java.lang.String needle, java.lang.String haystack, int start)
          Calls the lastIndex method of String class.
static java.lang.String left(java.lang.String s, int len)
          Autor: Francesc Ros�s Albiol Returns the string s left aligned, len characters length and padded with blanks.
static java.lang.String left(java.lang.String s, int len, char pad)
          Autor: Francesc Ros�s Albiol Here are some examples: left("1234", 2) - "12" left("1234", 6) - "1234 " left("1234", 6, '+') - "1234++" Creation date: (18/8/99 10:19:58)
static java.lang.String overlay(java.lang.String snew, java.lang.String target)
          Returns the string target, overlaid with the string snew from the beginning.
static java.lang.String overlay(java.lang.String snew, java.lang.String target, int n)
          Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length.
static java.lang.String overlay(java.lang.String snew, java.lang.String target, int n, int len)
          Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length.
static java.lang.String overlay(java.lang.String snew, java.lang.String target, int n, int len, char pad)
          Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length.
static int pos(char needle, java.lang.String haystack)
          Author: Xavier Navarro Ferrer Calls the index method of String class.
static int pos(char needle, java.lang.String haystack, int start)
          Author: Xavier Navarro Ferrer Calls the lastIndex method of String class.
static int pos(java.lang.String needle, java.lang.String haystack)
          Author: Xavier Navarro Ferrer Calls the lastIndex method of String class.
static int pos(java.lang.String needle, java.lang.String haystack, int start)
          Author: Xavier Navarro Ferrer Calls the indexOf method of String class.
static java.lang.String reverse(java.lang.String s)
          Returns string, swapped end for end.
static java.lang.String right(java.lang.String s, int len)
          Returns a string of length len containing the rightmost len characters of string.
static java.lang.String right(java.lang.String s, int len, char pad)
          Returns a string of length len containing the rightmost len characters of string.
static java.lang.String space(java.lang.String s)
          Returns the blank-delimited words in the receiving string, with one blank character between each word.
static java.lang.String space(java.lang.String s, char pad)
          Returns the blank-delimited words in the receiving string, with one pad character between each word.
static java.lang.String space(java.lang.String s, int n)
          Returns the blank-delimited words in the receiving string, with n blank characters between each word.
static java.lang.String space(java.lang.String s, int n, char pad)
          Returns the blank-delimited words in the receiving string, with n pad characters between each word.
static java.lang.String strip(java.lang.String cadena)
          Opci� per defecte de strip.
static java.lang.String strip(java.lang.String cadena, char charEsborrat)
          Opci� per defecte de strip quan no s'especifica d'on es treuen els car�cters.
static java.lang.String strip(java.lang.String cadena, java.lang.String deOn)
          Opci� per defecte de strip quan no s'especifica el car�cter que s'elimina.
static java.lang.String strip(java.lang.String cadena, java.lang.String deOn, char charEsborrat)
          Port de la funci� strip de REXX.
static java.lang.String subStr(java.lang.String s, int start)
          Returns the substring of the receiving string that begins at the nth character.
static java.lang.String subStr(java.lang.String s, int start, int len)
          Returns the sub-string of String s that begins at the start character, and is of length len [padded with blank characters if necessary].
static java.lang.String subStr(java.lang.String s, int start, int len, char pad)
          Returns the sub-string of String s that begins at the start character, and is of length len [padded with pad characters if necessary].
static java.lang.String subWord(java.lang.String s, int firstWordNum)
          Returns the substring of string that starts at the nth word, and is up to remaining blank-delimited words.
static java.lang.String subWord(java.lang.String s, int firstWordNum, int numWords)
          Returns the substring of string that starts at the nth word, and is up to length blank-delimited words.
static java.lang.String translate(java.lang.String s)
          Returns s with each character translated to another character or unchanged.
static java.lang.String translate(java.lang.String s, char pad)
          Returns s with each character translated to another character or unchanged.
static java.lang.String translate(java.lang.String s, java.lang.String tableo)
          Returns s with each character translated to another character or unchanged.
static java.lang.String translate(java.lang.String s, java.lang.String tableo, java.lang.String tablei)
          Returns s with each character translated to another character or unchanged.
static java.lang.String translate(java.lang.String s, java.lang.String tableo, java.lang.String tablei, char pad)
          Returns s with each character translated to another character or unchanged.
static java.lang.String UAcc(java.lang.String s)
           
static java.lang.String word(java.lang.String s, int n)
          Returns the nth blank-delimited word in string or returns the null string if fewer than n words are in string.
static int wordIndex(java.lang.String s, int n)
          Returns the position of the first character in the nth blank-delimited word in s or returns -1 if fewer than n words are in s or s is null or s haves length 0.
static int wordLength(java.lang.String s, int n)
          Returns the length of the nth blank-delimited word in string s or returns 0 if fewer than n words are in string s.
static int words(java.lang.String s)
          Returns the number of blank-delimited words in string.
static java.lang.String xrange()
          Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start (0x00) and end (0xFF).
static java.lang.String xrange(char start)
          Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start and 0xFF. start must be a single character.
static java.lang.String xrange(char start, char end)
          Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start and end.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

center

public static java.lang.String center(java.lang.String s,
                                      int len)
center(String,int) Returns a string of length len with s centered in it, with pad characters added as necessary to make up len. Creation date: (18/8/99 10:36:04)

Parameters:
s - The String to be centered.
len - int The length of final String
Returns:
A String with s centered in it.
See Also:
StringTools#center(String, int, char)

center

public static java.lang.String center(java.lang.String s,
                                      int len,
                                      char pad)
center(String,int,char) Returns a string of length len with s centered in it, with pad characters added as necessary to make up len. The len must be a positive whole number or zero. The default pad character is blank. If the string s is longer than len, it is truncated at both ends to fit. If an odd number of characters are truncated or added, the right-hand end loses or gains one more character than the left-hand end.

Here are some examples:

center("abc",7) // " ABC " center("abc",8,'-') // "--ABC---" center("The blue sky",8) // "e blue s" center("The blue sky",7) // "e blue " To avoid errors because of the difference between British and American spellings, this function can be called either centre or center. Creation date: (18/8/99 10:34:05)

Parameters:
s - The String to be centered.
len - int The length of final String
pad - The padding character
Returns:
A String with s centered in it.

centre

public static java.lang.String centre(java.lang.String s,
                                      int len)
Returns a string of length len with s centered in it, with pad characters added as necessary to make up len. Creation date: (18/8/99 10:38:13)

Parameters:
s - The String to be centered.
len - int The length of final String
Returns:
A String with s centered in it.
See Also:
StringTools#center(String, int, char)

centre

public static java.lang.String centre(java.lang.String s,
                                      int len,
                                      char pad)
Returns a string of length len with s centered in it, with pad characters added as necessary to make up len. Creation date: (18/8/99 10:37:11)

Parameters:
s - The String to be centered.
len - int The length of final String
pad - The padding character
Returns:
A String with s centered in it.
See Also:
StringTools#center(String, int, char)

changeStr

public static java.lang.String changeStr(java.lang.String needle,
                                         java.lang.String haystack,
                                         java.lang.String newneedle)
changeStr(String, String, String) Replaces all occurrences of needle in haystack with newneedle.

Examples:

StringTools.changeStr("1","101100","") - '000'
StringTools.changeStr("1","101100","X") - 'X0XX00

' Creation date: (19/8/99 9:13:49)

Parameters:
needle - Substring to be replaced
haystack - String to be changed
newneedle - Substring to replace needle
Returns:
A new String with the occurrences of needle replaced

compare

public static int compare(java.lang.String s1,
                          java.lang.String s2)
Returns -1 if the strings, string1 and string2, are identical. Otherwise, returns the position of the first character that does not match. The shorter string is padded with blank.

Parameters:
s1 - First element of compare
s2 - Second element of compare
Returns:
-1 if identical or the position of the first character that does not match
See Also:
StringTools#compare(String, String, char)

compare

public static int compare(java.lang.String s1,
                          java.lang.String s2,
                          char pad)
Returns -1 if the strings, string1 and string2, are identical. Otherwise, returns the position of the first character that does not match. The shorter string is padded on the right with pad if necessary. The default pad character is a blank. Here are some examples:

COMPARE('abc','abc') - -1 COMPARE('abc','ak') - 1 COMPARE('ab ','ab') - -1 COMPARE('ab ','ab',' ') - -1 COMPARE('ab ','ab','x') - 2 COMPARE('ab-- ','ab','-') - 4 Creation date: (19/8/99 12:25:00)

Parameters:
s1 - First element of compare
s2 - Second element of compare
pad - Padding for the shorter string
Returns:
-1 if identical or the position of the first character that does

copies

public static java.lang.String copies(char c,
                                      int times)
Autor: Francesc Ros�s Albiol Returns times concatenated copies of c.
The n must be a positive whole number or zero.

Here are some examples:

copies('a',3) - "aaa" copies('a',0) - "" Creation date: (18/8/99 10:28:56)

Modified: (11/6/99 09:01:23): if (times == 0) return null becomes [...] return "" like in Rexx.

Parameters:
c - char
times - int
Returns:
java.lang.String

copies

public static java.lang.String copies(java.lang.String s,
                                      int times)
Autor: Francesc Ros�s Albiol Returns times concatenated copies of c.
The n must be a positive whole number or zero.

Here are some examples:

copies("123",3) - "123123123" copies("123",0) - "" Creation date: (18/8/99 10:30:40)

Modified: (11/6/99 09:02:15): Added if (times == 0) return "" to do the same as in copies(char, int).

Parameters:
s - java.lang.String
times - int
Returns:
java.lang.String

countStr

public static int countStr(java.lang.String needle,
                           java.lang.String haystack)
Returns a count of the occurrences of needle in haystack that do not overlap.

Here are several examples:

countStr("1", "101101")) - 4 countStr("KK", "J0KKK0") - 1 Creation date: (19/8/99 11:57:31)

Parameters:
needle - java.lang.String
haystack - java.lang.String
Returns:
int

dataType

public static boolean dataType(java.lang.String value,
                               char type)
Checks if the string complies the type specification. Types can be: 'W' => Integer.

Parameters:
value - => the string we are checking the type.
type - => the type we are checking the string complies.
Returns:
true if the string complies the type false otherwise

delStr

public static java.lang.String delStr(java.lang.String s,
                                      int start)
Returns string after deleting the substring that begins at the nth character to the end (including the nth character). The n must be a positive whole number. If n is greater than the length of string, the function returns string unchanged. Creation date: (19/8/99 14:01:04)

Parameters:
s - java.lang.String
start - int
Returns:
java.lang.String

delStr

public static java.lang.String delStr(java.lang.String s,
                                      int start,
                                      int len)
Returns string after deleting the substring that begins at the nth character and is of length characters. If you omit length, or if length is greater than the number of characters from n to the end of string, the function deletes the rest of string (including the nth character). The length must be a positive whole number or zero. The n must be a positive whole number. If n is greater than the length of string, the function returns string unchanged.

Here are some examples:

delStr("abcd",2) - "ab" delStr("abcde",2,2) - "abe" delStr("abcde",5) - "abcde" Creation date: (19/8/99 13:36:13)

Parameters:
s - java.lang.String
start - int
len - int
Returns:
java.lang.String

delWord

public static java.lang.String delWord(java.lang.String s,
                                       int start)
Returns string after deleting the substring that starts at the startth word. The start must be a positive whole number. If start is greater than the number of words in string, the function returns string unchanged. The string deleted includes any blanks following the final word involved but none of the blanks preceding the first word involved. Creation date: (20/8/99 13:50:04)

Parameters:
s - java.lang.String
start - int
Returns:
java.lang.String

delWord

public static java.lang.String delWord(java.lang.String s,
                                       int start,
                                       int len)
Returns string after deleting the substring that starts at the startth word and is of len blank-delimited words. If you omit len, or if length is greater than the number of words from start to the end of string, the function deletes the remaining words in string (including the startth word). The length must be a positive whole number or zero. The start must be a positive whole number. If start is greater than the number of words in string, the function returns string unchanged. The string deleted includes any blanks following the final word involved but none of the blanks preceding the first word involved.

Here are some examples:

delWord("Now is the time",2,2) - 'Now time' delWord("Now is the time ",3) - 'Now is ' delWord("Now is the time",5) - 'Now is the time' delWord("Now is the time",3,1) - 'Now is time' Creation date: (20/8/99 13:28:50)

Parameters:
s - java.lang.String
start - int
len - int
Returns:
java.lang.String

insert

public static java.lang.String insert(java.lang.String snew,
                                      java.lang.String target)
Inserts the string new into the string target.

Here are some examples:

insert(" ","abcdef",3) - 'abc def' insert("123","abc",5,6) - 'abc 123 ' insert("123","abc",5,6,'+') - 'abc++123+++' insert("123","abc") - '123abc' insert("123","abc",,5,'-') - '123--abc' Creation date: (20/8/99 14:09:02)

Parameters:
snew - java.lang.String
target - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#insert(String, String, int, int, char)

insert

public static java.lang.String insert(java.lang.String snew,
                                      java.lang.String target,
                                      int n)
Inserts the string new into the string target after the nth character. The default value for n is 0, which means insert before the beginning of the string. n must positive whole number or zero. If n is greater than the length of the target string, padding is added before the string new also. The default pad character is a blank.

Here are some examples:

insert(" ","abcdef",3) - 'abc def' insert("123","abc",5,6) - 'abc 123 ' insert("123","abc",5,6,'+') - 'abc++123+++' insert("123","abc") - '123abc' insert("123","abc",,5,'-') - '123--abc' Creation date: (20/8/99 14:11:26)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
Returns:
java.lang.String
See Also:
StringTools#insert(String, String, int, int, char)

insert

public static java.lang.String insert(java.lang.String snew,
                                      java.lang.String target,
                                      int n,
                                      int len)
Inserts the string new, padded or truncated to length len, into the string target after the nth character. The default value for n is 0, which means insert before the beginning of the string. If specified, n and length must be positive whole numbers or zero. If n is greater than the length of the target string, padding is added before the string new also. The default value for len is the length of new. If len is less than the length of the string new, then Insert truncates new to length len. The pad character is a blank.

Here are some examples:

insert(" ","abcdef",3) - 'abc def' insert("123","abc",5,6) - 'abc 123 ' insert("123","abc",5,6,'+') - 'abc++123+++' insert("123","abc") - '123abc' insert("123","abc",,5,'-') - '123--abc' Creation date: (20/8/99 14:13:10)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
len - int
Returns:
java.lang.String
See Also:
StringTools#insert(String, String, int, int, char)

insert

public static java.lang.String insert(java.lang.String snew,
                                      java.lang.String target,
                                      int n,
                                      int len,
                                      char pad)
Inserts the string new, padded or truncated to length len, into the string target after the nth character. The default value for n is 0, which means insert before the beginning of the string. If specified, n and length must be positive whole numbers or zero. If n is greater than the length of the target string, padding is added before the string new also. The default value for len is the length of new. If len is less than the length of the string new, then Insert truncates new to length len. The default pad character is a blank.

Here are some examples:

insert(" ","abcdef",3) - 'abc def' insert("123","abc",5,6) - 'abc 123 ' insert("123","abc",5,6,'+') - 'abc++123+++' insert("123","abc") - '123abc' insert("123","abc",,5,'-') - '123--abc' Creation date: (20/8/99 14:02:11)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
len - int
pad - char
Returns:
java.lang.String

lastPos

public static int lastPos(char needle,
                          java.lang.String haystack)
Calls the lastIndex method of String class.

Creation date: (23/8/99 13:51:14)

Parameters:
needle - java.lang.String
haystack - java.lang.String
Returns:
int
See Also:
StringTools#lastPos(char, String, int)

lastPos

public static int lastPos(char needle,
                          java.lang.String haystack,
                          int start)
Calls the lastIndex method of String class.

I include this method for Rexx compatibility.

Here are some examples:

lastPos(' ',"abc def ghi") - 7 lastPos(' ',"abcdefghi") - -1 lastPos('xy',"efgxyz") - 3 lastPos(' ',"abc def ghi",6) - 3

Creation date: (23/8/99 13:51:14)

Parameters:
needle - char
haystack - java.lang.String
start - int
Returns:
int

lastPos

public static int lastPos(java.lang.String needle,
                          java.lang.String haystack)
Calls the lastIndex method of String class.

I include this method for Rexx compatibility.

Here are some examples:

lastPos(" ","abc def ghi") - 7 lastPos(" ","abcdefghi") - -1 lastPos("xy","efgxyz") - 3 lastPos(" ","abc def ghi",6) - 3

Creation date: (23/8/99 13:51:14)

Parameters:
needle - char
haystack - java.lang.String
Returns:
int
See Also:
StringTools#lastPos(String, String, int)

lastPos

public static int lastPos(java.lang.String needle,
                          java.lang.String haystack,
                          int start)
Calls the lastIndex method of String class.

I include this method for Rexx compatibility.

Here are some examples:

lastPos(" ","abc def ghi") - 7 lastPos(" ","abcdefghi") - -1 lastPos("xy","efgxyz") - 3 lastPos(" ","abc def ghi",6) - 3

Creation date: (23/8/99 13:51:14)

Parameters:
needle - java.lang.String
haystack - java.lang.String
start - int
Returns:
int

left

public static java.lang.String left(java.lang.String s,
                                    int len)
Autor: Francesc Ros�s Albiol Returns the string s left aligned, len characters length and padded with blanks.

Creation date: (18/8/99 10:20:49)

Parameters:
s - java.lang.String
len - int
Returns:
java.lang.String
See Also:
StringTools#left(String, int, char)

left

public static java.lang.String left(java.lang.String s,
                                    int len,
                                    char pad)
Autor: Francesc Ros�s Albiol Here are some examples:

left("1234", 2) - "12" left("1234", 6) - "1234 " left("1234", 6, '+') - "1234++" Creation date: (18/8/99 10:19:58)

Parameters:
s - java.lang.String
len - int
pad - char
Returns:
java.lang.String

overlay

public static java.lang.String overlay(java.lang.String snew,
                                       java.lang.String target)
Returns the string target, overlaid with the string snew from the beginning. (The overlay may extend beyond the end of the original target string.) Creation date: (24/8/99 13:21:11)

Parameters:
snew - java.lang.String
target - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#overlay(String, String, int, int, char)

overlay

public static java.lang.String overlay(java.lang.String snew,
                                       java.lang.String target,
                                       int n)
Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length. (The overlay may extend beyond the end of the original target string.) If n is greater than the length of the target string, blank padding is added before the new string. n must be a positive whole number. Creation date: (24/8/99 13:23:35)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
Returns:
java.lang.String
See Also:
StringTools#overlay(String, String, int, int, char)

overlay

public static java.lang.String overlay(java.lang.String snew,
                                       java.lang.String target,
                                       int n,
                                       int len)
Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length. (The overlay may extend beyond the end of the original target string.) len must be a positive whole number or zero. n must be a positive whole number. If n is greater than the length of the target string, blank padding is added before the new string. Creation date: (24/8/99 13:24:33)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
len - int
Returns:
java.lang.String

overlay

public static java.lang.String overlay(java.lang.String snew,
                                       java.lang.String target,
                                       int n,
                                       int len,
                                       char pad)
Returns the string target, which, starting at the nth character, is overlaid with the string snew, padded or truncated to len length. (The overlay may extend beyond the end of the original target string.) If you specify len, it must be a positive whole number or zero. The default value for len is the length of snew. If n is greater than the length of the target string, padding is added before the new string. The default pad character is a blank, and the default value for n is 0. If you specify n, it must be a positive whole number.

Here are some examples:

overlay(" ","abcdef",2); // 'ab def' overlay(".","abcdef",2,2); // 'ab. ef' overlay("qq","abcd"); // 'qqcd' overlay("qq","abcd",3); // 'abcqq' overlay("123","abc",4,6,'+'); // 'abc+123+++'

Creation date: (23/8/99 14:11:57)

Parameters:
snew - java.lang.String
target - java.lang.String
n - int
len - int
pad - char
Returns:
java.lang.String

pos

public static int pos(char needle,
                      java.lang.String haystack)
Author: Xavier Navarro Ferrer Calls the index method of String class.

Creation date: (19/05/2005 16:08:14)

Parameters:
needle - java.lang.String
haystack - java.lang.String
Returns:
int

pos

public static int pos(char needle,
                      java.lang.String haystack,
                      int start)
Author: Xavier Navarro Ferrer Calls the lastIndex method of String class.

I include this method for Rexx compatibility.

Here are some examples:

pos(' ',"abc def ghi") - 3 pos(' ',"abcdefghi") - -1 pos('x',"efgxyz") - 3

Creation date: (19/05/2005 16:08:14)

Parameters:
needle - char
haystack - java.lang.String
start - int
Returns:
int

pos

public static int pos(java.lang.String needle,
                      java.lang.String haystack)
Author: Xavier Navarro Ferrer Calls the lastIndex method of String class.

I include this method for Rexx compatibility.

Here are some examples:

pos(" ","abc def ghi") - 3 pos(" ","abcdefghi") - -1 pos("xy","efgxyz") - 3

Creation date: (19/05/2005 16:06:14)

Parameters:
needle - char
haystack - java.lang.String
Returns:
int
See Also:
StringTools#lastPos(String, String, int)

pos

public static int pos(java.lang.String needle,
                      java.lang.String haystack,
                      int start)
Author: Xavier Navarro Ferrer Calls the indexOf method of String class.

I include this method for Rexx compatibility.

Here are some examples:

pos(" ","abc def ghi") - 3 pos(" ","abcdefghi") - -1 pos("xy","efgxyz") - 3 pos(" ","abc def ghi",5) - 7

Creation date: (19/05/2005 16:04:14)

Parameters:
needle - java.lang.String
haystack - java.lang.String
start - int
Returns:
int

reverse

public static java.lang.String reverse(java.lang.String s)
Returns string, swapped end for end. Here are some examples:

reverse("cBA") - "ABc" reverse("XYZ ") - " ZYX"

Creation date: (24/8/99 11:10:00)

Parameters:
s - java.lang.String
Returns:
java.lang.String

right

public static java.lang.String right(java.lang.String s,
                                     int len)
Returns a string of length len containing the rightmost len characters of string. The string returned is blank padded with (or truncated) on the left as needed. The length must be a positive whole number or zero. Creation date: (18/8/99 10:26:50)

Parameters:
s - java.lang.String
len - int
Returns:
java.lang.String
See Also:
StringTools#right(String, int, char)

right

public static java.lang.String right(java.lang.String s,
                                     int len,
                                     char pad)
Returns a string of length len containing the rightmost len characters of string. The string returned is padded with pad characters (or truncated) on the left as needed. The default pad character is a blank. The len must be a positive whole number or zero.

Here are some examples:

right("abc d",8) // ' abc d' right("abc def",5) // 'c def' right("12",5,'0') // '00012'

Creation date: (18/8/99 10:26:21)

Modified: (11/6/99 08:56:43): Added if (len = s.length()) return s.

Parameters:
s - java.lang.String
len - int
pad - char
Returns:
java.lang.String

space

public static java.lang.String space(java.lang.String s)
Returns the blank-delimited words in the receiving string, with one blank character between each word. Creation date: (24/8/99 14:24:29)

Parameters:
s - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#space(String, int, char)

space

public static java.lang.String space(java.lang.String s,
                                     char pad)
Returns the blank-delimited words in the receiving string, with one pad character between each word. Creation date: (24/8/99 14:23:55)

Parameters:
s - java.lang.String
pad - char
Returns:
java.lang.String
See Also:
StringTools#space(String, int, char)

space

public static java.lang.String space(java.lang.String s,
                                     int n)
Returns the blank-delimited words in the receiving string, with n blank characters between each word. n must be a positive whole number or zero. If it is 0, all blanks are removed. Leading and trailing blanks are always removed. Creation date: (24/8/99 14:19:31)

Parameters:
s - java.lang.String
n - int
Returns:
java.lang.String
See Also:
StringTools#space(String, int, char)

space

public static java.lang.String space(java.lang.String s,
                                     int n,
                                     char pad)
Returns the blank-delimited words in the receiving string, with n pad characters between each word. If you specify n, it must be a positive whole number or zero. If it is 0, all blanks are removed. Leading and trailing blanks are always removed. The default for n is 1, and the default pad character is a blank. Creation date: (24/8/99 13:55:44)

Parameters:
s - java.lang.String
n - int
pad - char
Returns:
java.lang.String

strip

public static java.lang.String strip(java.lang.String cadena)
Opci� per defecte de strip. Veure documentaci� de strip(string cadena, string deOn, char charEsborrat) Default option of strip. See strip(string cadena, string deOn, char charEsborrat) documentation

Parameters:
cadena -
Returns:
La cadena sense blancs davant i darrera. The String cadena without leading and traling blanc chars.

strip

public static java.lang.String strip(java.lang.String cadena,
                                     char charEsborrat)
Opci� per defecte de strip quan no s'especifica d'on es treuen els car�cters. Veure documentaci� de strip(string cadena, string deOn, char charEsborrat). Default option of strip when you don't specify from where yo are removing the chars. See strip(string cadena, string deOn, char charEsborrat) documentation.

Parameters:
cadena -
Returns:
La cadena sense charEsborrat davant i darrera. The String cadena without leading and traling charEsborrat chars.

strip

public static java.lang.String strip(java.lang.String cadena,
                                     java.lang.String deOn)
Opci� per defecte de strip quan no s'especifica el car�cter que s'elimina. Veure documentaci� de strip(string cadena, string deOn, char charEsborrat). Default option of strip when you don't specify the char you are removing. See strip(string cadena, string deOn, char charEsborrat) documentation.

Parameters:
cadena -
Returns:
La cadena sense charEsborrat. The String cadena without charEsborrat chars.

strip

public static java.lang.String strip(java.lang.String cadena,
                                     java.lang.String deOn,
                                     char charEsborrat)
Port de la funci� strip de REXX. Aquesta funci� retorna una cadena a la qual se li han eliminat els caracters charEsborrat que tingui a: Si deOn = 'I' o 'L' del principi. Si deOn = 'F' o 'T' del final. Si deOn = 'D' o 'B' de l'inici i del final. deOn es pot especificar en min�scules i amb maj�scules. Port of strip function in REXX. This method returns a String without the charEsborrat at If deOn = 'I' o 'L' from the beggining. Si deOn = 'F' o 'T' from the end. Si deOn = 'D' o 'B' from both. You can deOn in UpperCase and LowerCase.

Parameters:
cadena -
deOn -
charEsborrat -
Returns:

subStr

public static java.lang.String subStr(java.lang.String s,
                                      int start)
Returns the substring of the receiving string that begins at the nth character. The n must be a positive whole number. Creation date: (19/8/99 13:10:02)

Parameters:
s - java.lang.String
start - int
Returns:
java.lang.String
See Also:
StringTools#subStr(String, int, int, char)

subStr

public static java.lang.String subStr(java.lang.String s,
                                      int start,
                                      int len)
Returns the sub-string of String s that begins at the start character, and is of length len [padded with blank characters if necessary]. start must be a positive whole number and len must be a non-negative whole number. If start is greater than s.length(), then only pad characters can be returned.

Parameters:
s - java.lang.String
start - int
len - int
Returns:
java.lang.String
See Also:
StringTools#subStr(String, int, int, char)

subStr

public static java.lang.String subStr(java.lang.String s,
                                      int start,
                                      int len,
                                      char pad)
Returns the sub-string of String s that begins at the start character, and is of length len [padded with pad characters if necessary]. start must be a positive whole number and len must be a non-negative whole number. If start is greater than s.length(), then only pad characters can be returned.

If len is omitted it defaults to be the rest of the string. The default pad character is a blank.

Here are some examples:

       subStr("abc", 1)          // "bc"
       subStr("abc", 1, 4)       // "bc  "
       subStr("abc", 4, 4)       // "    "
       subStr("abc", 1, 6, '.')  // "bc...."
       subStr("abc", 4, 6, '.')  // "......"
 
Creation date: (31/3/00 18:58:28)

Parameters:
s - java.lang.String
start - int
len - int
pad - char
Returns:
java.lang.String

subWord

public static java.lang.String subWord(java.lang.String s,
                                       int firstWordNum)
Returns the substring of string that starts at the nth word, and is up to remaining blank-delimited words. The firstWordNum must be a positive whole number greater than 1. The returned string never has leading or trailing blanks, but includes all blanks between the selected words. Creation date: (25/8/99 10:19:11)

Parameters:
s - java.lang.String
firstWordNum - int
Returns:
java.lang.String
See Also:
StringTools#subWord(String, int, int)

subWord

public static java.lang.String subWord(java.lang.String s,
                                       int firstWordNum,
                                       int numWords)
Returns the substring of string that starts at the nth word, and is up to length blank-delimited words. The firstWordNum must be a positive whole number greater than 1. If you omit numWords, it defaults to the number of remaining words in string. The returned string never has leading or trailing blanks, but includes all blanks between the selected words.

Here are some examples:

subWord("Now is the time",2,2); // "is the" subWord("Now is the time",3); // "the time" subWord("Now is the time",5); // "" Creation date: (19/8/99 9:07:30)

Parameters:
s - java.lang.String
firstWordNum - int
numWords - int Lenght in words.
Returns:
java.lang.String

translate

public static java.lang.String translate(java.lang.String s)
Returns s with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in s. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in s is used. The result string is always the same length as string s.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase a-z to uppercase A-Z), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults (when null) to xrange(0x00, 0xFF), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:

translate("abcdef"); // 'ABCDEF' translate("abcdef", '+'); // '++++++' translate("abcdef","12","ec"); // 'ab2d1f' translate("abcdef","12","abcd",'.'); // '12..ef' translate("APQRV",null,"PR"); // 'A Q V' translate("4123","abcd","1234"); // 'dabc' translate("APQRV",xrange((char)0x0,'Q')); // 'APQ '

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string. Creation date: (25/8/99 10:48:11)

Parameters:
s - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#translate(String, String, String, char)

translate

public static java.lang.String translate(java.lang.String s,
                                         char pad)
Returns s with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in s. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in s is used. The result string is always the same length as string s.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase a-z to uppercase A-Z), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults (when null) to xrange(0x00, 0xFF), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:

translate("abcdef"); // 'ABCDEF' translate("abcdef", '+'); // '++++++' translate("abcdef","12","ec"); // 'ab2d1f' translate("abcdef","12","abcd",'.'); // '12..ef' translate("APQRV",null,"PR"); // 'A Q V' translate("4123","abcd","1234"); // 'dabc' translate("APQRV",xrange((char)0x0,'Q')); // 'APQ '

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string. Creation date: (25/8/99 10:51:27)

Parameters:
s - java.lang.String
pad - char
Returns:
java.lang.String
See Also:
StringTools#translate(String, String, String, char)

translate

public static java.lang.String translate(java.lang.String s,
                                         java.lang.String tableo)
Returns s with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in s. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in s is used. The result string is always the same length as string s.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase a-z to uppercase A-Z), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults (when null) to xrange(0x00, 0xFF), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:

translate("abcdef"); // 'ABCDEF' translate("abcdef", '+'); // '++++++' translate("abcdef","12","ec"); // 'ab2d1f' translate("abcdef","12","abcd",'.'); // '12..ef' translate("APQRV",null,"PR"); // 'A Q V' translate("4123","abcd","1234"); // 'dabc' translate("APQRV",xrange((char)0x0,'Q')); // 'APQ '

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string. Creation date: (25/8/99 11:04:13)

Parameters:
s - java.lang.String
tableo - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#translate(String, String, String, char)

translate

public static java.lang.String translate(java.lang.String s,
                                         java.lang.String tableo,
                                         java.lang.String tablei)
Returns s with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in s. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in s is used. The result string is always the same length as string s.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase a-z to uppercase A-Z), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults (when null) to xrange(0x00, 0xFF), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:

translate("abcdef"); // 'ABCDEF' translate("abcdef", '+'); // '++++++' translate("abcdef","12","ec"); // 'ab2d1f' translate("abcdef","12","abcd",'.'); // '12..ef' translate("APQRV",null,"PR"); // 'A Q V' translate("4123","abcd","1234"); // 'dabc' translate("APQRV",xrange((char)0x0,'Q')); // 'APQ '

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string. Creation date: (25/8/99 10:59:13)

Parameters:
s - java.lang.String
tableo - java.lang.String
tablei - java.lang.String
Returns:
java.lang.String
See Also:
StringTools#translate(String, String, String, char)

translate

public static java.lang.String translate(java.lang.String s,
                                         java.lang.String tableo,
                                         java.lang.String tablei,
                                         char pad)
Returns s with each character translated to another character or unchanged. You can also use this function to reorder the characters in string.

The output table is tableo and the input translation table is tablei. TRANSLATE searches tablei for each character in s. If the character is found, then the corresponding character in tableo is used in the result string; if there are duplicates in tablei, the first (leftmost) occurrence is used. If the character is not found, the original character in s is used. The result string is always the same length as string s.

The tables can be of any length. If you specify neither translation table and omit pad, string is simply translated to uppercase (that is, lowercase a-z to uppercase A-Z), but, if you include pad, the language processor translates the entire string to pad characters. tablei defaults (when null) to xrange(0x00, 0xFF), and tableo defaults to the null string and is padded with pad or truncated as necessary. The default pad is a blank.

Here are some examples:

translate("abcdef"); // 'ABCDEF' translate("abcdef", '+'); // '++++++' translate("abcdef","12","ec"); // 'ab2d1f' translate("abcdef","12","abcd",'.'); // '12..ef' translate("APQRV",null,"PR"); // 'A Q V' translate("4123","abcd","1234"); // 'dabc' translate("APQRV",xrange((char)0x0,'Q')); // 'APQ '

The last example shows how to use the TRANSLATE function to reorder the characters in a string. In the example, the last character of any four-character string specified as the second argument would be moved to the beginning of the string. Creation date: (25/8/99 10:37:56)

Parameters:
s - java.lang.String
tableo - java.lang.String
tablei - java.lang.String
pad - char
Returns:
java.lang.String

UAcc

public static java.lang.String UAcc(java.lang.String s)

word

public static java.lang.String word(java.lang.String s,
                                    int n)
Returns the nth blank-delimited word in string or returns the null string if fewer than n words are in string. The n must be a positive whole number. This function is exactly equivalent to subWord(string,n,1).

Here are some examples:

word("Now is the time",3); // 'the' word("Now is the time",5); // ''

Creation date: (19/8/99 9:03:25)

Parameters:
s - java.lang.String
n - int Word number
Returns:
java.lang.String

wordIndex

public static int wordIndex(java.lang.String s,
                            int n)
Returns the position of the first character in the nth blank-delimited word in s or returns -1 if fewer than n words are in s or s is null or s haves length 0. The n must be a positive whole number.

Here are some examples:

wordIndex("Now is the time",3); // 7 wordIndex("Now is the time",6); // -1

Creation date: (25/8/99 13:15:33)

Parameters:
s - java.lang.String
n - int
Returns:
int

wordLength

public static int wordLength(java.lang.String s,
                             int n)
Returns the length of the nth blank-delimited word in string s or returns 0 if fewer than n words are in string s. The n must be a positive whole number.

Here are some examples:

wordLength("Now is the time",2); // 2 wordLength("Now comes the time",2); // 5 wordLength("Now is the time",6); // 0

Creation date: (25/8/99 13:28:28)

Parameters:
s - java.lang.String
n - int
Returns:
int

words

public static int words(java.lang.String s)
Returns the number of blank-delimited words in string.

Here are some examples:

words("Now is the time"); // 4 words(" "); // 0

In NetRexx the tab character is not a word delimiter. Only the blank character is a word delimited.

Creation date: (18/8/99 11:10:17)

Parameters:
s - java.lang.String
Returns:
int

xrange

public static java.lang.String xrange()
Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start (0x00) and end (0xFF).

Here are some examples:

xrange(); // [0x00 .. 0xFF]

Creation date: (25/8/99 12:33:12)

Returns:
java.lang.String

xrange

public static java.lang.String xrange(char start)
Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start and 0xFF. start must be a single character.

Here are some examples:

xrange('a'); // [a .. 0xFF]

Creation date: (25/8/99 12:32:11)

Parameters:
start - char
Returns:
java.lang.String

xrange

public static java.lang.String xrange(char start,
                                      char end)
Returns a string of all valid 1-byte encodings (in ascending order) between and including the values start and end. The default value for start is 0x00, and the default value for end is 0xFF. If start is greater than end, the values wrap from 0xFF to 0x00. If specified, start and end must be single characters.

Here are some examples:

xrange('a','f') - 'abcdef' xrange('i','j') - 'ij'

Creation date: (25/8/99 12:22:15)

Parameters:
start - char
end - char
Returns:
java.lang.String