使用 StringUtils 的 leftPad 和 rightPad 即可。

This commit is contained in:
2023-06-07 10:45:10 +08:00
parent 9e30ef5580
commit b2374e810b
2 changed files with 0 additions and 65 deletions

View File

@@ -1,31 +0,0 @@
package xyz.zhouxy.plusone.commons.util;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class StrUtilTests {
private static final Logger log = LoggerFactory.getLogger(StrUtilTests.class);
@Test
void testFillZero() {
char c = '=';
log.info(StrUtil.fillBefore("1", 6, c));
log.info(StrUtil.fillBefore("12", 6, c));
log.info(StrUtil.fillBefore("123", 6, c));
log.info(StrUtil.fillBefore("1234", 6, c));
log.info(StrUtil.fillBefore("12345", 6, c));
log.info(StrUtil.fillBefore("123456", 6, c));
log.info(StrUtil.fillBefore("1234567", 6, c));
log.info(StrUtil.fillBefore("12345678", 6, c));
log.info(StrUtil.fillAfter("1", 6, c));
log.info(StrUtil.fillAfter("12", 6, c));
log.info(StrUtil.fillAfter("123", 6, c));
log.info(StrUtil.fillAfter("1234", 6, c));
log.info(StrUtil.fillAfter("12345", 6, c));
log.info(StrUtil.fillAfter("123456", 6, c));
log.info(StrUtil.fillAfter("1234567", 6, c));
log.info(StrUtil.fillAfter("12345678", 6, c));
}
}