Class StringUtil


  • public class StringUtil
    extends Object
    Author:
    Kilian
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • charsNeeded

        public static int charsNeeded​(Number n)
        Calculate the number of characters needed to present the integer part of a number +1 if the number is negative.
         1234     -> 4
         -1234    -> 5
         12345    -> 5
         12345.12 -> 5
         
        Parameters:
        n - A number
        Returns:
        the character count of the integer part of the number
        Since:
        1.0.0 com.github.kilianB
      • centerText

        public static String centerText​(String text,
                                        String padding,
                                        int length)
        If the text can not be centered due to (length - textLength)%2 != 0 the string will be center left alligned with 1 padding string appended at the end of the string for consistent length.
        Parameters:
        text - the text to center
        padding - the padding symbol inserted left and right of the text (1 character long)
        length - the final length of the entire string
        Returns:
        the centered text as string.
        Since:
        1.0.0 com.github.kilianB
      • multiplyChar

        public static String multiplyChar​(String Char,
                                          int count)
        Construct a string with multiple chars concatenated x times
        Parameters:
        Char - the char of the final string
        count - the number of the chars appended after one another.
        Returns:
        The concat string.
        Since:
        1.0.0 com.github.kilianB
      • fillStringBeginning

        public static String fillStringBeginning​(String Char,
                                                 int desiredLength,
                                                 String content)
        Append the given char to the start of the string until the string has reached the given size
        Parameters:
        Char - The char or string to append
        desiredLength - The desired length of the final string
        content - the original string
        Returns:
        the string with the desired length and concatenated char
        Since:
        1.4.0 com.github.kilianB
      • fillString

        public static String fillString​(String Char,
                                        int desiredLength,
                                        String content)
        Append the given char to the end of the string until the string has reached the given size
        Parameters:
        Char - The char or string to append
        desiredLength - The desired length of the final string
        content - the original string
        Returns:
        the string with the desired length and concatenated char
        Since:
        1.0.0 com.github.kilianB