Package smile.util

Interface Strings


public interface Strings
String utility functions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final DecimalFormat
    Decimal format for floating numbers.
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static String
    fill(char ch, int len)
    Returns the string with a single repeated character to a specific length.
    static String
    format(double x)
    Returns the string representation of a floating number without trailing zeros.
    static String
    format(double x, boolean trailingZeros)
    Returns the string representation of a floating number.
    static String
    format(float x)
    Returns the string representation of a floating number without trailing zeros.
    static String
    format(float x, boolean trailingZeros)
    Returns the string representation of a floating number.
    static String
    Turn special characters into HTML character references.
    static String
    htmlEscape(String input, String encoding)
    Turn special characters into HTML character references.
    static boolean
    Returns true if the string is null or empty.
    static String
    leftPad(String s, int size, char padChar)
    Left pad a string with a specified character.
    static String
    ordinal(int i)
    Returns the string representation of ordinal number with suffix.
    static double[]
    Parses a double array in format '[1.0, 2.0, 3.0]'.
    static int[]
    Parses an integer array in format '[1, 2, 3]'.
    static String
    rightPad(String s, int size, char padChar)
    Right pad a string with a specified character.
    static String
    Unescapes a string that contains standard Java escape sequences.
  • Field Details

    • DECIMAL_FORMAT

      static final DecimalFormat DECIMAL_FORMAT
      Decimal format for floating numbers.
  • Method Details

    • isNullOrEmpty

      static boolean isNullOrEmpty(String s)
      Returns true if the string is null or empty.
      Parameters:
      s - the string.
      Returns:
      true if the string is null or empty.
    • unescape

      static String unescape(String s)
      Unescapes a string that contains standard Java escape sequences.
      Parameters:
      s - the string.
      Returns:
      the translated string.
    • htmlEscape

      static String htmlEscape(String input)
      Turn special characters into HTML character references.
      Parameters:
      input - the (unescaped) input string
      Returns:
      the escaped string
    • htmlEscape

      static String htmlEscape(String input, String encoding)
      Turn special characters into HTML character references.
      Parameters:
      input - the (unescaped) input string
      encoding - the name of a supported charset
      Returns:
      the escaped string
    • ordinal

      static String ordinal(int i)
      Returns the string representation of ordinal number with suffix.
      Parameters:
      i - the ordinal number.
      Returns:
      the string representation of ordinal number with suffix.
    • leftPad

      static String leftPad(String s, int size, char padChar)
      Left pad a string with a specified character.
      Parameters:
      s - the string to pad out, may be null
      size - the size to pad to
      padChar - the character to pad with
      Returns:
      left padded String or original String if no padding is necessary, null if null String input
    • rightPad

      static String rightPad(String s, int size, char padChar)
      Right pad a string with a specified character.
      Parameters:
      s - the string to pad out, may be null
      size - the size to pad to
      padChar - the character to pad with
      Returns:
      left padded String or original String if no padding is necessary, null if null String input
    • fill

      static String fill(char ch, int len)
      Returns the string with a single repeated character to a specific length.
      Parameters:
      ch - the character.
      len - the length of string.
      Returns:
      the string.
    • format

      static String format(float x)
      Returns the string representation of a floating number without trailing zeros.
      Parameters:
      x - a real number.
      Returns:
      the string representation.
    • format

      static String format(float x, boolean trailingZeros)
      Returns the string representation of a floating number.
      Parameters:
      x - a real number.
      trailingZeros - the flag if removes the trailing zeros.
      Returns:
      the string representation.
    • format

      static String format(double x)
      Returns the string representation of a floating number without trailing zeros.
      Parameters:
      x - a real number.
      Returns:
      the string representation.
    • format

      static String format(double x, boolean trailingZeros)
      Returns the string representation of a floating number.
      Parameters:
      x - a real number.
      trailingZeros - the flag if removes the trailing zeros.
      Returns:
      the string representation.
    • parseIntArray

      static int[] parseIntArray(String s)
      Parses an integer array in format '[1, 2, 3]'. Returns null if s is null or empty.
      Parameters:
      s - the string.
      Returns:
      the array.
    • parseDoubleArray

      static double[] parseDoubleArray(String s)
      Parses a double array in format '[1.0, 2.0, 3.0]'. Returns null if s is null or empty.
      Parameters:
      s - the string.
      Returns:
      the array.