Here you can find the source of addLeadingCharacter(String s, char c, int len)
Parameter | Description |
---|---|
s | the source string. |
c | the leading character(s) to be added. |
len | the length of the target string. |
public static String addLeadingCharacter(String s, char c, int len)
//package com.java2s; /* //w w w . j a v a2 s . c o m * Copyright(c) 2005 Center for E-Commerce Infrastructure Development, The * University of Hong Kong (HKU). All Rights Reserved. * * This software is licensed under the GNU GENERAL PUBLIC LICENSE Version 2.0 [1] * * [1] http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ public class Main { /** * Adds specified leading characters to the specified length. Nothing will * be done if the length of the given string is equal to or greater than the * specified length. * * @param s the source string. * @param c the leading character(s) to be added. * @param len the length of the target string. * @return the string after adding the specified leading character(s). */ public static String addLeadingCharacter(String s, char c, int len) { while (s != null && s.length() < len) { s = c + s; } return s; } }