def addForLR(voldStr, vaddStr, vlength, vleft=True):
"""
数字前补0可以补"0"也可以补""
# print(tools.addForLR(1123,'0',6));
# print(tools.addForLR(1123,'0',6,False));
@param voldStr 旧字符串
@param vaddStr 添加字符串
@param vlength 字符长度
@param vleft
<p>
true:左补字符
</p>
<p>
false:右补字符
</p>
@author zhangjun
@return 重组后的数据
"""
if (voldStr == None or vaddStr == None):
return voldStr;
voldStr = str(voldStr);
vaddStr = str(vaddStr);
vlen = len(voldStr);
if (vlen < vlength) :
while (vlen < vlength) :
sb = '';
if (vleft) :
sb = vaddStr + voldStr;
else :
sb = voldStr + vaddStr;
voldStr = sb;
vlen = len(voldStr);
return voldStr;
本文为张军原创文章,转载无需和我联系,但请注明来自张军的军军小站,个人博客http://www.zhangjunbk.com