Class StringUtil

java.lang.Object
org.locationtech.jtstest.util.StringUtil

public class StringUtil extends Object
Useful string utilities
Version:
1.7
Author:
jaquino
  • Field Details

    • newLine

      public static final String newLine
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • removeFromEnd

      public static String removeFromEnd(String s, String strToRemove)
    • capitalize

      public static String capitalize(String s)
      Capitalizes the given string.
      Parameters:
      s - the string to capitalize
      Returns:
      the capitalized string
    • isInteger

      public static boolean isInteger(String s)
      Returns true if s can be converted to an int.
    • getStackTrace

      public static String getStackTrace(Throwable t)
      Returns an throwable's stack trace
    • getStackTrace

      public static String getStackTrace(Throwable t, int depth)
    • getTimeString

      public static String getTimeString(long milliseconds)
      Converts the milliseconds value into a String of the form "9d 22h 15m 8s".
    • containsIgnoreCase

      public static boolean containsIgnoreCase(String string, String substring)
      Returns true if substring is indeed a substring of string. Case-insensitive.
    • contains

      public static boolean contains(String string, String substring)
      Returns true if substring is indeed a substring of string.
    • replace

      public static String replace(String str, char oldChar, String newStr)
      Returns a string with all occurrences of oldChar replaced by newStr
    • stringOfChar

      public static String stringOfChar(char ch, int count)
      Returns a String of the given length consisting entirely of the given character
    • indent

      public static String indent(String original, int spaces)
    • toUpperCase

      public static Vector toUpperCase(Vector v)
      Returns the elements of v in uppercase
    • toLowerCase

      public static Vector toLowerCase(List v)
      Returns the elements of v in lowercase
    • toCommaDelimitedStringInQuotes

      public static String toCommaDelimitedStringInQuotes(Collection c)
      Returns the elements of c separated by commas and enclosed in single-quotes
    • toCommaDelimitedString

      public static String toCommaDelimitedString(Collection c)
      Returns the elements of c separated by commas. c must not be empty.
    • fromCommaDelimitedString

      public static List fromCommaDelimitedString(String s)
      Converts the comma-delimited string into a List of trimmed strings.
    • toStringNeverNull

      public static String toStringNeverNull(Object o)
      If s is null, returns "null"; otherwise, returns s.
    • replace

      public static void replace(StringBuffer orig, String o, String n, boolean all)
      Replaces all instances of the String o with the String n in the StringBuffer orig if all is true, or only the first instance if all is false. Posted by Steve Chapel invalid input: '<'schapel@breakthr.com> on UseNet
    • replaceAll

      public static String replaceAll(String original, String oldSubstring, String newSubstring)
      Returns original with all occurrences of oldSubstring replaced by newSubstring
    • replaceFirst

      public static String replaceFirst(String original, String oldSubstring, String newSubstring)
      Returns original with the first occurrenc of oldSubstring replaced by newSubstring
    • leftPad

      public static String leftPad(String original, int length, char padChar)
      Pads the String with the given character until it has the given length. If original is longer than the given length, returns original.
    • rightPad

      public static String rightPad(String original, int length, char padChar)
      Pads the String with the given character until it has the given length. If original is longer than the given length, returns original.
    • stripHTMLTags

      public static String stripHTMLTags(String original)
      Removes the HTML tags from the given String, inserting line breaks at appropriate places. Needs a little work.
    • format

      public static String format(double d, int decimals)
      Returns d as a string truncated to the specified number of decimal places
    • wrap

      public static String wrap(String s, int n)
      Line-wraps a string s by inserting CR-LF instead of the first space after the nth columns.
    • removeVowels

      public static String removeVowels(String s)
      Removes vowels from the string. Case-insensitive.
    • removeVowelsSkipStarts

      public static String removeVowelsSkipStarts(String s)
      Removes vowels from the string except those that start words. Case-insensitive.
    • removeConsecutiveDuplicates

      public static String removeConsecutiveDuplicates(String s)
      Replaces consecutive instances of characters with single instances. Case-insensitive.
    • indexOfIgnoreParentheses

      public static int indexOfIgnoreParentheses(char c, String s, int start)
      Returns the position of the first occurrence of the given character found in s starting at start. Ignores text within pairs of parentheses. Returns -1 if no occurrence is found.
    • replace

      public static String replace(String original, String oldSubstring, String newSubstring, boolean all)
      Returns original with occurrences of oldSubstring replaced by newSubstring. Set all to true to replace all occurrences, or false to replace the first occurrence only.
    • escapeHTML

      public static String escapeHTML(String s)
    • currentMethodName

      public static String currentMethodName()