Java String Align Left alignLeft(CharSequence cs, int width, char c)

Here you can find the source of alignLeft(CharSequence cs, int width, char c)

Description

align Left

License

Apache License

Declaration

public static String alignLeft(CharSequence cs, int width, char c) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String alignLeft(CharSequence cs, int width, char c) {
        if (null == cs)
            return null;
        int length = cs.length();
        if (length >= width)
            return cs.toString();
        return new StringBuilder().append(cs).append(dup(c, width - length)).toString();
    }// w ww.  ja v a2 s  .  c  om

    public static String dup(CharSequence cs, int num) {
        if (isEmpty(cs) || num <= 0)
            return "";
        StringBuilder sb = new StringBuilder(cs.length() * num);
        for (int i = 0; i < num; i++)
            sb.append(cs);
        return sb.toString();
    }

    public static String dup(char c, int num) {
        if (c == 0 || num < 1)
            return "";
        StringBuilder sb = new StringBuilder(num);
        for (int i = 0; i < num; i++)
            sb.append(c);
        return sb.toString();
    }

    public static boolean isEmpty(CharSequence cs) {
        return null == cs || cs.length() == 0;
    }
}

Related

  1. alignLeft(String sLine, int iSize)
  2. alignLeft(String str, int length)
  3. alignLeft(String str, int size)
  4. alignLeft(String substring, int totalWidth, char fill)