Java Doc for StringHelper.java in  » Template-Engine » ostermillerutils » com » Ostermiller » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.Ostermiller.util.StringHelper

StringHelper
public class StringHelper (Code)
Utilities for String formatting, manipulation, and queries. More information about this class is available from ostermiller.org.
author:
   Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
since:
   ostermillerutils 1.00.00




Method Summary
public static  booleancontainsAny(String s, String[] terms)
     Tests to see if the given string contains any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleancontainsAnyIgnoreCase(String s, String[] terms)
     Tests to see if the given string contains any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleanendsWithAny(String s, String[] terms)
     Tests to see if the given string ends with any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleanendsWithAnyIgnoreCase(String s, String[] terms)
     Tests to see if the given string ends with any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleanequalsAny(String s, String[] terms)
     Tests to see if the given string equals any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleanequalsAnyIgnoreCase(String s, String[] terms)
     Tests to see if the given string equals any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  StringescapeHTML(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.

public static  StringescapeJavaLiteral(String s)
     Replaces characters that are not allowed in a Java style string literal with their escape characters.
public static  StringescapeRegularExpressionLiteral(String s)
    
public static  StringescapeSQL(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.

public static  PatterngetContainsAnyIgnoreCasePattern(String[] terms)
     Compile a pattern that can will match a string if the string contains any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getContainsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetContainsAnyPattern(String[] terms)
     Compile a pattern that can will match a string if the string contains any of the given terms.

Usage:
boolean b = getContainsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetEndsWithAnyIgnoreCasePattern(String[] terms)
     Compile a pattern that can will match a string if the string ends with any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetEndsWithAnyPattern(String[] terms)
     Compile a pattern that can will match a string if the string ends with any of the given terms.

Usage:
boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetEqualsAnyIgnoreCasePattern(String[] terms)
     Compile a pattern that can will match a string if the string equals any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getEqualsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetEqualsAnyPattern(String[] terms)
     Compile a pattern that can will match a string if the string equals any of the given terms.

Usage:
boolean b = getEqualsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetStartsWithAnyIgnoreCasePattern(String[] terms)
     Compile a pattern that can will match a string if the string starts with any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  PatterngetStartsWithAnyPattern(String[] terms)
     Compile a pattern that can will match a string if the string starts with any of the given terms.

Usage:
boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings.

public static  Stringjoin(String[] array)
     Join all the elements of a string array into a single String.

If the given array empty an empty string will be returned.

public static  Stringjoin(String[] array, String delimiter)
     Join all the elements of a string array into a single String.

If the given array empty an empty string will be returned.

public static  Stringmidpad(String s, int length)
     Pad the beginning and end of the given String with spaces until the String is of the given length.
public static  Stringmidpad(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.
public static  Stringpostpad(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.
Parameters:
  length - desired length of result.

public static  Stringpostpad(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.
Parameters:
  length - desired length of result.
Parameters:
  c - padding character.

public static  Stringprepad(String s, int length)
     Pad the beginning 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.
Parameters:
  length - desired length of result.

public static  Stringprepad(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.
Parameters:
  s - String to be padded.
Parameters:
  length - desired length of result.
Parameters:
  c - padding character.

public static  Stringreplace(String s, String find, String replace)
     Replace occurrences of a substring. StringHelper.replace("1-2-3", "-", "|");
result: "1|2|3"
StringHelper.replace("-1--2-", "-", "|");
result: "|1||2|"
StringHelper.replace("123", "", "|");
result: "123"
StringHelper.replace("1-2---3----4", "--", "|");
result: "1-2|-3||4"
StringHelper.replace("1-2---3----4", "--", "---");
result: "1-2----3------4"

Parameters:
  s - String to be modified.
Parameters:
  find - String to find.
Parameters:
  replace - String to replace.
public static  String[]split(String s, String delimiter)
     Split the given String into tokens.

This method is meant to be similar to the split function in other programming languages but it does not use regular expressions.

public static  String[]splitIncludeDelimiters(String s, String delimiter)
     Split the given String into tokens.
public static  booleanstartsWithAny(String s, String[] terms)
     Tests to see if the given string starts with any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  booleanstartsWithAnyIgnoreCase(String s, String[] terms)
     Tests to see if the given string starts with any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms.

public static  Stringtrim(String s, String c)
     Trim any of the characters contained in the second string from the beginning and end of the first.
Parameters:
  s - String to be trimmed.
Parameters:
  c - list of characters to trim from s.
public static  StringunescapeHTML(String s)
     Turn any HTML escape entities in the string into characters and return the resulting string.
Parameters:
  s - String to be un-escaped.



Method Detail
containsAny
public static boolean containsAny(String s, String[] terms)(Code)
Tests to see if the given string contains any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getContainsAnyPattern(String[])
Parameters:
  s - String that may contain any of the given terms.
Parameters:
  terms - list of substrings that may be contained in the given string. true iff one of the terms is a substring of the given string.
since:
   ostermillerutils 1.02.25




containsAnyIgnoreCase
public static boolean containsAnyIgnoreCase(String s, String[] terms)(Code)
Tests to see if the given string contains any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getContainsAnyIgnoreCasePattern(String[])
Parameters:
  s - String that may contain any of the given terms.
Parameters:
  terms - list of substrings that may be contained in the given string. true iff one of the terms is a substring of the given string.
since:
   ostermillerutils 1.02.25




endsWithAny
public static boolean endsWithAny(String s, String[] terms)(Code)
Tests to see if the given string ends with any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getEndsWithAnyPattern(String[])
Parameters:
  s - String that may end with any of the given terms.
Parameters:
  terms - list of strings that may end with the given string. true iff the given string ends with one of the given terms.
since:
   ostermillerutils 1.02.25




endsWithAnyIgnoreCase
public static boolean endsWithAnyIgnoreCase(String s, String[] terms)(Code)
Tests to see if the given string ends with any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getEndsWithAnyIgnoreCasePattern(String[])
Parameters:
  s - String that may end with any of the given terms.
Parameters:
  terms - list of strings that may end with the given string. true iff the given string ends with one of the given terms.
since:
   ostermillerutils 1.02.25




equalsAny
public static boolean equalsAny(String s, String[] terms)(Code)
Tests to see if the given string equals any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getEqualsAnyPattern(String[])
Parameters:
  s - String that may equal any of the given terms.
Parameters:
  terms - list of strings that may equal the given string. true iff one of the terms is equal to the given string.
since:
   ostermillerutils 1.02.25




equalsAnyIgnoreCase
public static boolean equalsAnyIgnoreCase(String s, String[] terms)(Code)
Tests to see if the given string equals any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getEqualsAnyIgnoreCasePattern(String[])
Parameters:
  s - String that may equal any of the given terms.
Parameters:
  terms - list of strings that may equal the given string. true iff one of the terms is equal to the given string.
since:
   ostermillerutils 1.02.25




escapeHTML
public static String escapeHTML(String s)(Code)
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 escaped String
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




escapeJavaLiteral
public static String escapeJavaLiteral(String s)(Code)
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 escaped String
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00



escapeRegularExpressionLiteral
public static String escapeRegularExpressionLiteral(String s)(Code)
Escapes characters that have special meaning to regular expressions
Parameters:
  s - String to be escaped escaped String
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.02.25



escapeSQL
public static String escapeSQL(String s)(Code)
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 place holders.
Parameters:
  s - String to be escaped escaped String
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




getContainsAnyIgnoreCasePattern
public static Pattern getContainsAnyIgnoreCasePattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string contains any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getContainsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it contains any of the terms.
since:
   ostermillerutils 1.02.25




getContainsAnyPattern
public static Pattern getContainsAnyPattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string contains any of the given terms.

Usage:
boolean b = getContainsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it contains any of the terms.
since:
   ostermillerutils 1.02.25




getEndsWithAnyIgnoreCasePattern
public static Pattern getEndsWithAnyIgnoreCasePattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string ends with any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it ends with any of the terms.
since:
   ostermillerutils 1.02.25




getEndsWithAnyPattern
public static Pattern getEndsWithAnyPattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string ends with any of the given terms.

Usage:
boolean b = getEndsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it ends with any of the terms.
since:
   ostermillerutils 1.02.25




getEqualsAnyIgnoreCasePattern
public static Pattern getEqualsAnyIgnoreCasePattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string equals any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getEqualsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it equals any of the terms.
since:
   ostermillerutils 1.02.25




getEqualsAnyPattern
public static Pattern getEqualsAnyPattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string equals any of the given terms.

Usage:
boolean b = getEqualsAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it equals any of the terms.
since:
   ostermillerutils 1.02.25




getStartsWithAnyIgnoreCasePattern
public static Pattern getStartsWithAnyIgnoreCasePattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string starts with any of the given terms.

Case is ignored when matching using Unicode case rules.

Usage:
boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it starts with any of the terms.
since:
   ostermillerutils 1.02.25




getStartsWithAnyPattern
public static Pattern getStartsWithAnyPattern(String[] terms)(Code)
Compile a pattern that can will match a string if the string starts with any of the given terms.

Usage:
boolean b = getStartsWithAnyPattern(terms).matcher(s).matches();

If multiple strings are matched against the same set of terms, it is more efficient to reuse the pattern returned by this function.
Parameters:
  terms - Array of search strings. Compiled pattern that can be used to match a string to see if it starts with any of the terms.
since:
   ostermillerutils 1.02.25




join
public static String join(String[] array)(Code)
Join all the elements of a string array into a single String.

If the given array empty an empty string will be returned. Null elements of the array are allowed and will be treated like empty Strings.
Parameters:
  array - Array to be joined into a string. Concatenation of all the elements of the given array.
throws:
  NullPointerException - if array is null.
since:
   ostermillerutils 1.05.00




join
public static String join(String[] array, String delimiter)(Code)
Join all the elements of a string array into a single String.

If the given array empty an empty string will be returned. Null elements of the array are allowed and will be treated like empty Strings.
Parameters:
  array - Array to be joined into a string.
Parameters:
  delimiter - String to place between array elements. Concatenation of all the elements of the given array with the the delimiter in between.
throws:
  NullPointerException - if array or delimiter is null.
since:
   ostermillerutils 1.05.00




midpad
public static String midpad(String s, int length)(Code)
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.
Parameters:
  length - desired length of result. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




midpad
public static String midpad(String s, int length, char c)(Code)
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.
Parameters:
  length - desired length of result.
Parameters:
  c - padding character. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




postpad
public static String postpad(String s, int length)(Code)
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.
Parameters:
  length - desired length of result. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




postpad
public static String postpad(String s, int length, char c)(Code)
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.
Parameters:
  length - desired length of result.
Parameters:
  c - padding character. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




prepad
public static String prepad(String s, int length)(Code)
Pad the beginning 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.
Parameters:
  length - desired length of result. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




prepad
public static String prepad(String s, int length, char c)(Code)
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.
Parameters:
  s - String to be padded.
Parameters:
  length - desired length of result.
Parameters:
  c - padding character. padded String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




replace
public static String replace(String s, String find, String replace)(Code)
Replace occurrences of a substring. StringHelper.replace("1-2-3", "-", "|");
result: "1|2|3"
StringHelper.replace("-1--2-", "-", "|");
result: "|1||2|"
StringHelper.replace("123", "", "|");
result: "123"
StringHelper.replace("1-2---3----4", "--", "|");
result: "1-2|-3||4"
StringHelper.replace("1-2---3----4", "--", "---");
result: "1-2----3------4"

Parameters:
  s - String to be modified.
Parameters:
  find - String to find.
Parameters:
  replace - String to replace. a string with all the occurrences of the string to find replaced.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00



split
public static String[] split(String s, String delimiter)(Code)
Split the given String into tokens.

This method is meant to be similar to the split function in other programming languages but it does not use regular expressions. Rather the String is split on a single String literal.

Unlike java.util.StringTokenizer which accepts multiple character tokens as delimiters, the delimiter here is a single String literal.

Each null token is returned as an empty String. Delimiters are never returned as tokens.

If there is no delimiter because it is either empty or null, the only element in the result is the original String.

StringHelper.split("1-2-3", "-");
result: {"1","2","3"}
StringHelper.split("-1--2-", "-");
result: {"","1","","2",""}
StringHelper.split("123", "");
result: {"123"}
StringHelper.split("1-2---3----4", "--");
result: {"1-2","-3","","4"}

Parameters:
  s - String to be split.
Parameters:
  delimiter - String literal on which to split. an array of tokens.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00




splitIncludeDelimiters
public static String[] splitIncludeDelimiters(String s, String delimiter)(Code)
Split the given String into tokens. Delimiters will be returned as tokens.

This method is meant to be similar to the split function in other programming languages but it does not use regular expressions. Rather the String is split on a single String literal.

Unlike java.util.StringTokenizer which accepts multiple character tokens as delimiters, the delimiter here is a single String literal.

Each null token is returned as an empty String. Delimiters are never returned as tokens.

If there is no delimiter because it is either empty or null, the only element in the result is the original String.

StringHelper.split("1-2-3", "-");
result: {"1","-","2","-","3"}
StringHelper.split("-1--2-", "-");
result: {"","-","1","-","","-","2","-",""}
StringHelper.split("123", "");
result: {"123"}
StringHelper.split("1-2--3---4----5", "--");
result: {"1-2","--","3","--","-4","--","","--","5"}

Parameters:
  s - String to be split.
Parameters:
  delimiter - String literal on which to split. an array of tokens.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.05.00




startsWithAny
public static boolean startsWithAny(String s, String[] terms)(Code)
Tests to see if the given string starts with any of the given terms.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getStartsWithAnyPattern(String[])
Parameters:
  s - String that may start with any of the given terms.
Parameters:
  terms - list of strings that may start with the given string. true iff the given string starts with one of the given terms.
since:
   ostermillerutils 1.02.25




startsWithAnyIgnoreCase
public static boolean startsWithAnyIgnoreCase(String s, String[] terms)(Code)
Tests to see if the given string starts with any of the given terms.

Case is ignored when matching using Unicode case rules.

This implementation is more efficient than the brute force approach of testing the string against each of the terms. It instead compiles a single regular expression that can test all the terms at once, and uses that expression against the string.

This is a convenience method. If multiple strings are tested against the same set of terms, it is more efficient not to compile the regular expression multiple times.
See Also:   StringHelper.getStartsWithAnyIgnoreCasePattern(String[])
Parameters:
  s - String that may start with any of the given terms.
Parameters:
  terms - list of strings that may start with the given string. true iff the given string starts with one of the given terms.
since:
   ostermillerutils 1.02.25




trim
public static String trim(String s, String c)(Code)
Trim any of the characters contained in the second string from the beginning and end of the first.
Parameters:
  s - String to be trimmed.
Parameters:
  c - list of characters to trim from s. trimmed String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00



unescapeHTML
public static String unescapeHTML(String s)(Code)
Turn any HTML escape entities in the string into characters and return the resulting string.
Parameters:
  s - String to be un-escaped. un-escaped String.
throws:
  NullPointerException - if s is null.
since:
   ostermillerutils 1.00.00



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.