左填充

static string leftPad(string& originalStr,int size,char padChar = '')
{
int len = originalStr.size();
if (size < len)
{
return originalStr;
}
int k = size - len;
string tmp("");
while (k >= 1)
{
tmp += padChar;
k--;
}
string result = tmp + originalStr;
return result;
}

posted @ 2017-08-28 19:20  MAC10  阅读(146)  评论(0编辑  收藏  举报