日期:2014-05-20 浏览次数:20857 次
public String transeferStr(String orgin)
{
int poslength = 30;
int length = orgin.length();
int remaining = poslength - length;
if(remaining > 0)
{
StringBuilder sb = new StringBuilder();
for(int i = 0;i < remaining ;i++)
{
sb .append(0);
}
sb.append(orgin);
return sb.toString();
}
return orgin.toString();
}
String test ="3123123";
String value = StringUtils.leftPad(test, 10, "0");
ystem.out.println(value);
package testPackage;
public class StringTest {
public static void main(String[] args) {
//假设必须15位长
int fullLength = 15;
//假设输入123456
StringBuilder input = new StringBuilder("123456");
//预先定义一个15位0
StringBuilder zero = new StringBuilder("000000000000000");
String result = zero.substring(0, zero.length() - input.length()) + input;
System.out.println(result);
}
}