de.vc.util

## Class Strings

- java.lang.Object
- - de.vc.util.Strings

-     public class Strings
      extends java.lang.Object

  Utilities for Strings.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `WHITESPACES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Strings()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `appendLeadingChar(java.lang.String str, int length, char c)`
    `static int` | `countCharacter(java.lang.String str, char c, boolean excludeQuoted)` Counts the number of `c` within `str`.
    `static java.lang.String` | `decodeEscapedHexChars(java.lang.String str, char escapeChar)` Decodes characters within `str` that are escaped by `escapeChar` followed by 2 hexadecimal digits.
    `static byte[]` | `decodeFromBase64(java.lang.String base64)`
    `static byte[]` | `decodeFromHexString(java.lang.String hex)`
    `static java.lang.String` | `encodeToBase64(byte[] bytes)`
    `static java.lang.String` | `encodeToHexString(byte[] bytes)`
    `static java.lang.String` | `filter(java.lang.String str, java.lang.String allowedChars)`
    `static java.lang.String[]` | `getTokensRegardingQuotes(java.lang.String str, java.lang.String whitespaces)`
    `static java.lang.String[]` | `getTokensRegardingQuotes(java.lang.String str, java.lang.String whitespaces, boolean inclQuotes)`
    `static java.lang.String` | `parseAttribute(java.lang.String string, java.lang.String key, boolean caseSensitive)` Parses an attribute.
    `static java.util.Map` | `parseAttributes(java.lang.String string, boolean lowercaseKeys)` Parses a String for a collection of attributes from a String.
    `static java.lang.String` | `readQuoted(java.lang.String str)` Reads a quoted text at begin of a String
    `static java.lang.String` | `readValue(java.lang.String str, java.lang.String key, boolean caseSensitive)` Deprecated. User parseAttribute instead.
    `static java.lang.String` | `removeChar(java.lang.String str, char c)`
    `static java.lang.String` | `replace(java.lang.String str, java.lang.String oldSub, java.lang.String newSub)`
    `static java.lang.String` | `reverse(java.lang.String str)`
    `static java.lang.String` | `subString(java.lang.String s, int begin, int end)`
    `static java.lang.String` | `toHexString(int number, int minimumLength)` Converts a number into a hex string with leading zeros.
    `static java.lang.String` | `trim(java.lang.String string, java.lang.String whitespaces)`
    `static java.lang.String` | `trim2null(java.lang.String s)` Trims a string and returns null if the string was empty.
    `static java.lang.String` | `trimInMiddle(java.lang.String string, int maxSize)` Trims a string by cropping characters in the middle.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### WHITESPACES

          public static final java.lang.String WHITESPACES

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Strings

          public Strings()

  - ### Method Detail

    - #### toHexString

          public static java.lang.String toHexString(int number,
                                     int minimumLength)

      Converts a number into a hex string with leading zeros.
      Parameters:
        `number` - Number
        `minimumLength` - Minimum length of hex string (padded with 0).
      Returns:
        Hex representation of `number`.

    - #### appendLeadingChar

          public static java.lang.String appendLeadingChar(java.lang.String str,
                                           int length,
                                           char c)

    - #### parseAttributes

          public static final java.util.Map parseAttributes(java.lang.String string,
                                      boolean lowercaseKeys)

      Parses a String for a collection of attributes from a String. An attribute is introduced by a key, followed by eq-symbol and finally the value.
      Parameters:
        `string` - String that contains parameters.
        `lowercaseKeys` - Put all keys in lower case letters.
      Returns:
        Parameter map.

    - #### parseAttribute

          public static final java.lang.String parseAttribute(java.lang.String string,
                                        java.lang.String key,
                                        boolean caseSensitive)

      Parses an attribute.
      Parameters:
        `string` - String
        `key` - Key
        `caseSensitive` - boolean
      Returns:
        String

    - #### readValue

          public static final java.lang.String readValue(java.lang.String str,
                                   java.lang.String key,
                                   boolean caseSensitive)

      Deprecated. User parseAttribute instead.
      Reads a value that is identified by a key.
      Examples:
      readValue("name=ANY", "name", true) returns "ANY"
      readValue("name=ANY street='a steet'", "street", true) returns "a steet"
      Parameters:
        `str` - A string that contains keys and values.
        `key` - A key.
        `caseSensitive` - true, if key is case-sensitive.
      Returns:
        Value of key or NULL if not defined.

    - #### decodeEscapedHexChars

          public static java.lang.String decodeEscapedHexChars(java.lang.String str,
                                               char escapeChar)

      Decodes characters within `str` that are escaped by `escapeChar` followed by 2 hexadecimal digits.
      For example decodeEscapedHexChars("Hello%20you",'%') returns "Hello you".
      Parameters:
        `str` - String
        `escapeChar` - char
      Returns:
        String

    - #### replace

          public static java.lang.String replace(java.lang.String str,
                                 java.lang.String oldSub,
                                 java.lang.String newSub)

    - #### readQuoted

          public static java.lang.String readQuoted(java.lang.String str)

      Reads a quoted text at begin of a String
      Parameters:
        `str` - String
      Returns:
        Quotet begin.

    - #### getTokensRegardingQuotes

          public static java.lang.String[] getTokensRegardingQuotes(java.lang.String str,
                                                    java.lang.String whitespaces)

    - #### getTokensRegardingQuotes

          public static java.lang.String[] getTokensRegardingQuotes(java.lang.String str,
                                                    java.lang.String whitespaces,
                                                    boolean inclQuotes)

    - #### encodeToHexString

          public static java.lang.String encodeToHexString(byte[] bytes)

    - #### decodeFromHexString

          public static byte[] decodeFromHexString(java.lang.String hex)

    - #### encodeToBase64

          public static java.lang.String encodeToBase64(byte[] bytes)
                                                 throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### decodeFromBase64

          public static byte[] decodeFromBase64(java.lang.String base64)
                                         throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### subString

          public static java.lang.String subString(java.lang.String s,
                                   int begin,
                                   int end)

    - #### trimInMiddle

          public static java.lang.String trimInMiddle(java.lang.String string,
                                      int maxSize)

      Trims a string by cropping characters in the middle. If the `string` is larger than `maxSize` then some characters in the middle of `string` are cropped and replaced by `...`.
      Parameters:
        `string` - String
        `maxSize` - Maximum size.
      Returns:
        Trimmed string.

    - #### countCharacter

          public static int countCharacter(java.lang.String str,
                           char c,
                           boolean excludeQuoted)

      Counts the number of `c` within `str`.
      Parameters:
        `str` - String
        `c` - Character to count.
        `excludeQuoted` - true to exclude characters within quotation.
      Returns:
        Number of `c`.

    - #### reverse

          public static final java.lang.String reverse(java.lang.String str)

    - #### removeChar

          public static final java.lang.String removeChar(java.lang.String str,
                                    char c)

    - #### filter

          public static final java.lang.String filter(java.lang.String str,
                                java.lang.String allowedChars)

    - #### trim

          public static final java.lang.String trim(java.lang.String string,
                              java.lang.String whitespaces)

    - #### trim2null

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

      Trims a string and returns null if the string was empty.
      Parameters:
        `s` - String
      Returns:
        Trimmed string or null.

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.