需求:字符串A,处理成字符串B
输出结果要求:将字符串处理成icount长度的字符串,
如果字符串A的长度大于icount则依据字符串B进行截取;
如果字符串的长度小于icount的长度则进行补位。
/// <summary> /// 数字纠正,补全11位: /// 如果位数大于11位则进行截取; /// 如果长度小于(11-basenum长度)则进行补位; /// </summary> /// <param name="strnum">原始字符</param> /// <param name="basenum">填补字符串</param> /// <param name="icount">长度</param> /// <returns>补位后的字符串</returns> private string NumCorrect(string strnum, string basenum, int icount = 11) { string newnnum = strnum; int strnumlength = strnum.Length; if (strnumlength == icount) { return newnnum; } int idex = strnum.IndexOf(basenum); if (idex >= 0) { newnnum = strnum.Substring(idex, icount); } else { int basenumlength = basenum.Length; int iadd = strnumlength + basenumlength; if (strnumlength < icount && iadd >= icount) { int difference = icount - strnumlength; newnnum = basenum.Substring(0,difference) + strnum; } } return newnnum; }