Here you can find the source of LeftAdjust(String s, int len, char pad)
s
on the right side with pad
until len
characters.
Parameter | Description |
---|---|
s | String to adjust |
len | Number of characters after the adjustment |
pad | Pad/fill character |
pad
character until it is len
characters long
public static String LeftAdjust(String s, int len, char pad)
//package com.java2s; /* jvmtest - Testing your VM Copyright (C) 20009, Guenther Wimpassinger //from w w w .ja v a2s . c o m This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Pad the string <code>s</code> on the right side with <code>pad</code> * until <code>len</code> characters. If <code>s</code> is * longer the right part is truncated. * @param s String to adjust * @param len Number of characters after the adjustment * @param pad Pad/fill character * @return The adjusted string padded with the <code>pad</code> * character until it is <code>len</code> characters long */ public static String LeftAdjust(String s, int len, char pad) { char[] ca = new char[len]; int k; if (s == null) { k = 0; } else { k = s.length(); } for (int i = 0; i < len && i < k; i++) { ca[i] = s.charAt(i); } for (int i = k; i < len; i++) { ca[i] = pad; } return new String(ca, 0, ca.length); } }