java补空格_JAVA STRING 对象自动补齐空格

之所以补空格因为 该长度不一的时候 有时候会导致 ORACLE数据库的子SQL 变得很多多. 导致非常慢.

ORACLE 11G 11.2.01 打补丁风险太大

只好补空格让其一直. 注意采用的字节长度

public static String formatStr(String str, int length)

{

if (str == null)

{

str="";

}

int strLen = str.getBytes().length;

if (strLen == length)

{

return str;

} else if (strLen < length)

{

int temp = length - strLen;

String tem = "";

for (int i = 0; i < temp; i++)

{

tem = tem + " ";

}

return str + tem;

} else

{

return str.substring(0, length);

}

}

原文:http://blog.csdn.net/zengmuansha/article/details/46047517


版权声明:本文为weixin_39837727原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。