nl.knowledgeplaza.util
Class StringUtil

java.lang.Object
  extended by nl.knowledgeplaza.util.StringUtil

public class StringUtil
extends java.lang.Object

This class contains several String helper methods.

Version:
$Revision: 1.6 $
Author:
$Author: toeukpap $

Field Summary
static java.lang.String FILTERCHARS_BACKSLASH
           
static java.lang.String FILTERCHARS_DIGITS
           
static java.lang.String FILTERCHARS_LOWERLETTERS
           
static java.lang.String FILTERCHARS_PUNCTUATION
           
static java.lang.String FILTERCHARS_QUOTES
           
static java.lang.String FILTERCHARS_UPPERLETTERS
           
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String byteArrayToString(byte[] ba)
          Returns a byte array as a java string
static java.lang.String byteArrayToString(byte[] ba, int offset, int len)
          Returns a byte array as a java string
static java.lang.String byteToHex(byte b)
          Returns hex String representation of byte b
static java.lang.String byteToHex(byte[] b)
          Returns hex String representation of bytes b
static java.lang.String charToHex(char c)
          Returns hex String representation of char c
static boolean contains(java.lang.String str, char chr)
          Return true if the string contains the other character.
static boolean contains(java.lang.String str, java.lang.String sub)
          Return true if the string contains the other string.
static java.lang.String convertStandardTypesToString(java.lang.Object o)
           
static java.lang.Object convertStringToStandardTypes(java.lang.String s, java.lang.Class c)
           
static int count(java.lang.String text, java.lang.String pattern)
          counts how many times the given pattern occurs in the given text.
static int countWords(java.lang.String s, java.lang.String delimiter)
           
static java.lang.String deleteChars(java.lang.String str, java.lang.String chars)
          Delete all occurencies of certain characters in a string.
static boolean equalsTrueInSomeForm(java.lang.String s)
          all of "true", "yes" or "1", case insensitive and trimmed, are considered 'true'
static java.lang.String escapeForSQL(java.lang.String in)
          Helper function for escaping strings that should be used in SQL queries.
static java.lang.String escapeHTML(java.lang.String s)
          Replaces characters that may be confused by a HTML parser with their equivalent character entity references.
static java.lang.String escapeHTMLTag(java.lang.String aTagFragment)
          Replace characters having special meaning inside HTML tags with their escaped equivalents, using character entities such as '&'.
static java.lang.String escapeJavaLiteral(java.lang.String s)
          Replaces characters that are not allowed in a Java style string literal with their escape characters.
static java.lang.String escapeRegex(java.lang.String aRegexFragment)
          Replace characters having special meaning in regular expressions with their escaped equivalents.
static java.lang.String escapeSQL(java.lang.String s)
          Replaces characters that may be confused by an SQL parser with their equivalent escape characters.
static java.lang.String escapeString(java.lang.String in)
          Escape all String delimiter with \
static java.lang.String escapeURL(java.lang.String aURLFragment)
          Synonym for URLEncoder.encode(String, "UTF-8").
static java.lang.String filter(java.lang.String original, java.lang.String filter)
          Only allow those characters that are present in the filter filter("aAAcA-1%23", "ABCDEFGHIJKLMNOPQRSTIUVWXYZ1234567890") returns AAA123
static java.lang.String filterChars(java.lang.String from, java.lang.String chars)
          Leave any of the characters in chars in the string
static java.lang.String firstWord(java.lang.String s)
           
static java.lang.String flattenString(java.lang.String in)
          throw away all line feeds
static java.lang.String fromJavaStringLiteral(java.lang.String str)
          Convert a backslash notation into a String (e.g.
static java.lang.String ifEmpty(java.lang.String s, java.lang.String d)
          if s is null or length=0 return d else s
static java.lang.String ifNull(java.lang.String s, java.lang.String d)
          if s is null return d else s
static java.lang.String insertAt(java.lang.String s, int startIdx, java.lang.String s2)
          insert a piece into a string
static boolean isEmpty(java.lang.String s)
          true if s is null or length=0
static boolean isMatch(java.lang.String pattern, java.lang.String string)
          This method does a wildcard match (using * and ?) on pattern with the given string.
static boolean isNotEmpty(java.lang.String s)
          true if s != null and length > 0
static java.lang.String left(java.lang.String aString, int len)
          equivalent to the basic "left" function
static java.lang.String makeFirstLetterLowercase(java.lang.String id)
           
static java.lang.String makeFirstLetterUppercase(java.lang.String id)
           
static java.lang.String midpad(java.lang.String s, int length)
          Pad the beginning and end of the given String with spaces until the String is of the given length.
static java.lang.String midpad(java.lang.String s, int length, char c)
          Pad the beginning and end of the given String with the given character until the result is the desired length.
static int nthIndexOfWord(java.lang.String s, java.lang.String word, int n)
          return the index of the nth occurence of word.
static java.lang.String nthWord(java.lang.String s, int nr, char delimiter)
          return the nthWord delimited by a delimiter
static java.lang.String postpad(java.lang.String s, int length)
          Pad the end of the given String with spaces until the String is of the given length.
static java.lang.String postpad(java.lang.String s, int length, char c)
          Append the given character to the String until the result is the desired length.
static java.lang.String prepad(java.lang.String s, int length, char c)
          Pre-pend the given character to the String until the result is the desired length.
static java.lang.String pullToken(java.lang.StringBuffer buf, java.lang.String delim)
          Remove a token from a the beginning of a StringBuffer, and return it.
static java.lang.String removeChars(java.lang.String from, java.lang.String chars)
          Remove any of the characters in chars from the string
static java.lang.String removeSubstring(java.lang.String s, int startIdx, int endIdx)
          snip a portion from a string and return the remainder
static java.lang.String repeat(java.lang.String s, int n)
          Repeat string S for N times
static java.lang.String replace(java.lang.String strReplaceInThis, java.lang.String strReplaceThis, java.lang.String strWithThis)
          replace function for strings instead of chars
static java.lang.String replace(java.lang.String strReplaceInThis, java.lang.String strReplaceThis, java.lang.String strWithThis, int fromIdx, int toIdx)
          Replace a substring in a string but only between the specified indexes (substring).
static java.lang.String replaceFirst(java.lang.String strReplaceInThis, java.lang.String strReplaceThis, java.lang.String strWithThis)
          replace function for strings instead of chars, only replace first occurence
static java.lang.String replaceSubstring(java.lang.String s, int startIdx, int endIdx, java.lang.String s2)
          remove a piece from within a string and insert new at that location
static java.lang.String reverse(java.lang.String s)
          reverse a string
static java.lang.String right(java.lang.String aString, int len)
          equivalent to the basic "right" function
static byte[] stringToByteArray(java.lang.String str)
          Returns a java string as a byte array
static byte[] stringToByteArray(java.lang.String str, int offset, int length)
          Returns a java string as a byte array
static java.lang.String subWords(java.lang.String s, int start)
          Get the string starting from the start'th word until end.
static java.lang.String subWords(java.lang.String s, int start, int end)
          Get the string starting from the start'th word ending before the end'th word
static java.lang.String toHexString(byte[] b)
           
static java.lang.String toJavaStringLiteral(java.lang.String str, boolean useRaw)
          Convert a String into backslash notation (e.g.
static java.lang.String[] tokenizeDelimitedToArray(java.lang.String toBeDelimited, java.lang.String delimiters)
          Tokenize on each character
static java.lang.String[] tokenizeDelimitedToArray(java.lang.String toBeDelimited, java.lang.String delimiters, boolean returnDelims)
          Return an array of String from a String containing delimited values.
static java.lang.String toRoman(int num)
          Convert an integer to Roman notation
static java.lang.String translate(java.lang.String str, java.lang.String fromChars, java.lang.String toChars)
          Translate characters in a string, like the t// operator in perl.
static java.lang.String unescapeHTML(java.lang.String s)
          Turn any HTML escape entities in the string into characters and return the resulting string.
static java.lang.String wrap(java.lang.String text, int width)
          lines may not be longer than X characters (words are cut)
static java.lang.String wrapApproximate(java.lang.String aString, int approximateWidth)
          wraps a string to a maximum length by inserting newlines
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

FILTERCHARS_LOWERLETTERS

public static final java.lang.String FILTERCHARS_LOWERLETTERS
See Also:
Constant Field Values

FILTERCHARS_UPPERLETTERS

public static final java.lang.String FILTERCHARS_UPPERLETTERS
See Also:
Constant Field Values

FILTERCHARS_DIGITS

public static final java.lang.String FILTERCHARS_DIGITS
See Also:
Constant Field Values

FILTERCHARS_PUNCTUATION

public static final java.lang.String FILTERCHARS_PUNCTUATION
See Also:
Constant Field Values

FILTERCHARS_BACKSLASH

public static final java.lang.String FILTERCHARS_BACKSLASH
See Also:
Constant Field Values

FILTERCHARS_QUOTES

public static final java.lang.String FILTERCHARS_QUOTES
See Also:
Constant Field Values
Constructor Detail

StringUtil

public StringUtil()
Method Detail

tokenizeDelimitedToArray

public static java.lang.String[] tokenizeDelimitedToArray(java.lang.String toBeDelimited,
                                                          java.lang.String delimiters,
                                                          boolean returnDelims)
Return an array of String from a String containing delimited values. For example "a,b,c" will return a String[3] {"a","b","c"}. Tokenize on each character

Parameters:
delimited - the String value to tokenize
delimiters - the delimiter ("," or ";" for example)
Returns:
an array of String delimited value

tokenizeDelimitedToArray

public static java.lang.String[] tokenizeDelimitedToArray(java.lang.String toBeDelimited,
                                                          java.lang.String delimiters)
Tokenize on each character

Parameters:
toBeDelimited -
delimiters -
Returns:

stringToByteArray

public static byte[] stringToByteArray(java.lang.String str)
Returns a java string as a byte array


stringToByteArray

public static byte[] stringToByteArray(java.lang.String str,
                                       int offset,
                                       int length)
Returns a java string as a byte array


byteArrayToString

public static java.lang.String byteArrayToString(byte[] ba,
                                                 int offset,
                                                 int len)
Returns a byte array as a java string


byteArrayToString

public static java.lang.String byteArrayToString(byte[] ba)
Returns a byte array as a java string


wrapApproximate

public static java.lang.String wrapApproximate(java.lang.String aString,
                                               int approximateWidth)
wraps a string to a maximum length by inserting newlines

Parameters:
aString -
approximateWidth -
Returns:

wrap

public static java.lang.String wrap(java.lang.String text,
                                    int width)
lines may not be longer than X characters (words are cut)


left

public static java.lang.String left(java.lang.String aString,
                                    int len)
equivalent to the basic "left" function

Parameters:
aString -
len -
Returns:

right

public static java.lang.String right(java.lang.String aString,
                                     int len)
equivalent to the basic "right" function

Parameters:
aString -
len -
Returns:

replace

public static java.lang.String replace(java.lang.String strReplaceInThis,
                                       java.lang.String strReplaceThis,
                                       java.lang.String strWithThis)
replace function for strings instead of chars

Parameters:
strReplaceInThis - in this string
strReplaceThis - this orignal text
strWithThis - with this text
Returns:

replaceFirst

public static java.lang.String replaceFirst(java.lang.String strReplaceInThis,
                                            java.lang.String strReplaceThis,
                                            java.lang.String strWithThis)
replace function for strings instead of chars, only replace first occurence

Parameters:
strReplaceInThis - in this string
strReplaceThis - this orignal text
strWithThis - with this text
Returns:

replace

public static java.lang.String replace(java.lang.String strReplaceInThis,
                                       java.lang.String strReplaceThis,
                                       java.lang.String strWithThis,
                                       int fromIdx,
                                       int toIdx)
Replace a substring in a string but only between the specified indexes (substring).

Parameters:
strReplaceInThis -
strReplaceThis -
strWithThis -
fromIdx -
toIdx -
Returns:

escapeURL

public static java.lang.String escapeURL(java.lang.String aURLFragment)
Synonym for URLEncoder.encode(String, "UTF-8").

Used to ensure that HTTP query strings are in proper form, by escaping special characters such as spaces.

An example use case for this method is a login scheme in which, after successful login, the user is redirected to the "original" target destination. Such a target might be passed around as a request parameter. Such a request parameter will have a URL as its value, as in "LoginTarget=Blah.jsp?this=that&blah=boo", and would need to be URL-encoded in order to escape its special characters.

It is important to note that if a query string appears in an HREF attribute, then there are two issues - ensuring the query string is valid HTTP (it is URL-encoded), and ensuring it is valid HTML (ensuring the ampersand is escaped).


escapeHTMLTag

public static java.lang.String escapeHTMLTag(java.lang.String aTagFragment)
Replace characters having special meaning inside HTML tags with their escaped equivalents, using character entities such as '&'.

The escaped characters are :

Use cases for this method include :


escapeRegex

public static java.lang.String escapeRegex(java.lang.String aRegexFragment)
Replace characters having special meaning in regular expressions with their escaped equivalents.

The escaped characters include :


escapeHTML

public static java.lang.String escapeHTML(java.lang.String s)
Replaces characters that may be confused by a HTML parser with their equivalent character entity references.

Any data that will appear as text on a web page should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users. A common mistake in CGI programming is to ask a user for data and then put that data on a web page. For example:

 Server: What is your name?
 User: <b>Joe<b>
 Server: Hello Joe, Welcome
If the name is put on the page without checking that it doesn't contain HTML code or without sanitizing that HTML code, the user could reformat the page, insert scripts, and control the the content on your web server.

This method will replace HTML characters such as > with their HTML entity reference (&gt;) so that the html parser will be sure to interpret them as plain text rather than HTML or script.

This method should be used for both data to be displayed in text in the html document, and data put in form elements. For example:
<html><body>This in not a &lt;tag&gt; in HTML</body></html>
and
<form><input type="hidden" name="date" value="This data could be &quot;malicious&quot;"></form>
In the second example, the form data would be properly be resubmitted to your cgi script in the URLEncoded format:
This data could be %22malicious%22

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.

unescapeHTML

public static java.lang.String unescapeHTML(java.lang.String s)
Turn any HTML escape entities in the string into characters and return the resulting string.

Parameters:
s - String to be unescaped.
Returns:
unescaped String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

escapeSQL

public static java.lang.String escapeSQL(java.lang.String s)
Replaces characters that may be confused by an SQL parser with their equivalent escape characters.

Any data that will be put in an SQL query should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users.

For example if you had the following SQL query:
"SELECT * FROM addresses WHERE name='" + name + "' AND private='N'"
Without this function a user could give " OR 1=1 OR ''='" as their name causing the query to be:
"SELECT * FROM addresses WHERE name='' OR 1=1 OR ''='' AND private='N'"
which will give all addresses, including private ones.
Correct usage would be:
"SELECT * FROM addresses WHERE name='" + StringHelper.escapeSQL(name) + "' AND private='N'"

Another way to avoid this problem is to use a PreparedStatement with appropriate placeholders.

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.

escapeJavaLiteral

public static java.lang.String escapeJavaLiteral(java.lang.String s)
Replaces characters that are not allowed in a Java style string literal with their escape characters. Specifically quote ("), single quote ('), new line (\n), carriage return (\r), and backslash (\), and tab (\t) are escaped.

Parameters:
s - String to be escaped
Returns:
escaped String, null if the input was null

prepad

public static java.lang.String prepad(java.lang.String s,
                                      int length,
                                      char c)
Pre-pend the given character to the String until the result is the desired length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added. Most notably this can be used to generate leading zero's: prepad("" + some_int_being_one, 5, '0') results in "00001".

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.

postpad

public static java.lang.String postpad(java.lang.String s,
                                       int length)
Pad the end of the given String with spaces until the String is of the given length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.

postpad

public static java.lang.String postpad(java.lang.String s,
                                       int length,
                                       char c)
Append the given character to the String until the result is the desired length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.

midpad

public static java.lang.String midpad(java.lang.String s,
                                      int length)
Pad the beginning and end of the given String with spaces until the String is of the given length. The result is that the original String is centered in the middle of the new string.

If the number of characters to pad is even, then the padding will be split evenly between the beginning and end, otherwise, the extra character will be added to the end.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.

repeat

public static java.lang.String repeat(java.lang.String s,
                                      int n)
Repeat string S for N times

Parameters:
s -
n -
Returns:

midpad

public static java.lang.String midpad(java.lang.String s,
                                      int length,
                                      char c)
Pad the beginning and end of the given String with the given character until the result is the desired length. The result is that the original String is centered in the middle of the new string.

If the number of characters to pad is even, then the padding will be split evenly between the beginning and end, otherwise, the extra character will be added to the end.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.

toHexString

public static java.lang.String toHexString(byte[] b)

byteToHex

public static java.lang.String byteToHex(byte b)
Returns hex String representation of byte b

Parameters:
b -
Returns:

byteToHex

public static java.lang.String byteToHex(byte[] b)
Returns hex String representation of bytes b

Parameters:
b -
Returns:

charToHex

public static java.lang.String charToHex(char c)
Returns hex String representation of char c

Parameters:
c -
Returns:

isMatch

public static boolean isMatch(java.lang.String pattern,
                              java.lang.String string)
This method does a wildcard match (using * and ?) on pattern with the given string. It returns true if the given string is represented by the given pattern.

Parameters:
pattern - the wildcard pattern to use
string - the string to check against pattern
Returns:
true if string represented by pattern, false else

subWords

public static java.lang.String subWords(java.lang.String s,
                                        int start)
Get the string starting from the start'th word until end.

Parameters:
s - string that contains words separated by blanks

subWords

public static java.lang.String subWords(java.lang.String s,
                                        int start,
                                        int end)
Get the string starting from the start'th word ending before the end'th word


nthWord

public static java.lang.String nthWord(java.lang.String s,
                                       int nr,
                                       char delimiter)
return the nthWord delimited by a delimiter


firstWord

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

nthIndexOfWord

public static int nthIndexOfWord(java.lang.String s,
                                 java.lang.String word,
                                 int n)
return the index of the nth occurence of word. -1 if word can't be found n times


escapeString

public static java.lang.String escapeString(java.lang.String in)
Escape all String delimiter with \


escapeForSQL

public static java.lang.String escapeForSQL(java.lang.String in)
Helper function for escaping strings that should be used in SQL queries.


flattenString

public static java.lang.String flattenString(java.lang.String in)
throw away all line feeds


countWords

public static int countWords(java.lang.String s,
                             java.lang.String delimiter)

translate

public static java.lang.String translate(java.lang.String str,
                                         java.lang.String fromChars,
                                         java.lang.String toChars)
Translate characters in a string, like the t// operator in perl.


deleteChars

public static java.lang.String deleteChars(java.lang.String str,
                                           java.lang.String chars)
Delete all occurencies of certain characters in a string.


pullToken

public static java.lang.String pullToken(java.lang.StringBuffer buf,
                                         java.lang.String delim)
Remove a token from a the beginning of a StringBuffer, and return it. The delim argument is a string of possible characters that may ends the token. This method does not return an empty ("") string - instead null is returned.

This is a "helper" method, should probably be found in some other class. Let me know if you find a suitable replacement.

Parameters:
buf - the line with words to remove a word from
delim - string of characters that may end token
Returns:
the removed leading token (null if no word available)

contains

public static boolean contains(java.lang.String str,
                               java.lang.String sub)
Return true if the string contains the other string.

This method is provided merely for improved code readability. It is equivalent to str.indexOf(sub) != -1.


contains

public static boolean contains(java.lang.String str,
                               char chr)
Return true if the string contains the other character.

This method is provided merely for improved code readability. It is equivalent to str.indexOf(chr) != -1.


toJavaStringLiteral

public static java.lang.String toJavaStringLiteral(java.lang.String str,
                                                   boolean useRaw)
Convert a String into backslash notation (e.g. newline as backslash-n).

Parameters:
str -
useRaw -
Returns:

fromJavaStringLiteral

public static java.lang.String fromJavaStringLiteral(java.lang.String str)
Convert a backslash notation into a String (e.g. backslash-n as newline).

Parameters:
str -
useRaw -
Returns:

filter

public static java.lang.String filter(java.lang.String original,
                                      java.lang.String filter)
Only allow those characters that are present in the filter filter("aAAcA-1%23", "ABCDEFGHIJKLMNOPQRSTIUVWXYZ1234567890") returns AAA123

Parameters:
original -
filter -
Returns:

replaceSubstring

public static java.lang.String replaceSubstring(java.lang.String s,
                                                int startIdx,
                                                int endIdx,
                                                java.lang.String s2)
remove a piece from within a string and insert new at that location

Parameters:
s -
startIdx -
endIdx -
Returns:

removeSubstring

public static java.lang.String removeSubstring(java.lang.String s,
                                               int startIdx,
                                               int endIdx)
snip a portion from a string and return the remainder

Parameters:
s -
startIdx -
endIdx -
Returns:

insertAt

public static java.lang.String insertAt(java.lang.String s,
                                        int startIdx,
                                        java.lang.String s2)
insert a piece into a string

Parameters:
s -
startIdx -
s2 -
Returns:

reverse

public static java.lang.String reverse(java.lang.String s)
reverse a string


toRoman

public static java.lang.String toRoman(int num)
Convert an integer to Roman notation

Parameters:
num -
Returns:

convertStandardTypesToString

public static java.lang.String convertStandardTypesToString(java.lang.Object o)
Parameters:
s -
c -
Returns:

convertStringToStandardTypes

public static java.lang.Object convertStringToStandardTypes(java.lang.String s,
                                                            java.lang.Class c)
Parameters:
s -
c -
Returns:

ifNull

public static java.lang.String ifNull(java.lang.String s,
                                      java.lang.String d)
if s is null return d else s

Parameters:
s -
d -
Returns:

ifEmpty

public static java.lang.String ifEmpty(java.lang.String s,
                                       java.lang.String d)
if s is null or length=0 return d else s

Parameters:
s -
d -
Returns:

isEmpty

public static boolean isEmpty(java.lang.String s)
true if s is null or length=0

Parameters:
s -
Returns:

isNotEmpty

public static boolean isNotEmpty(java.lang.String s)
true if s != null and length > 0

Parameters:
s -
Returns:

removeChars

public static java.lang.String removeChars(java.lang.String from,
                                           java.lang.String chars)
Remove any of the characters in chars from the string

Parameters:
from -
chars -

filterChars

public static java.lang.String filterChars(java.lang.String from,
                                           java.lang.String chars)
Leave any of the characters in chars in the string

Parameters:
from -
chars -

equalsTrueInSomeForm

public static boolean equalsTrueInSomeForm(java.lang.String s)
all of "true", "yes" or "1", case insensitive and trimmed, are considered 'true'

Parameters:
s -
Returns:

makeFirstLetterLowercase

public static java.lang.String makeFirstLetterLowercase(java.lang.String id)
Parameters:
id -
Returns:

makeFirstLetterUppercase

public static java.lang.String makeFirstLetterUppercase(java.lang.String id)
Parameters:
id -
Returns:

count

public static int count(java.lang.String text,
                        java.lang.String pattern)
counts how many times the given pattern occurs in the given text. Example: count("ababababab", "abab") returns 2.



Copyright © 2010. All Rights Reserved.