文件以name-1.pdf、name-2.pdf、name-3.pdf......name-80.pdf命名,传到数据库中排序混乱:1之后为10,2之后是20,所以要把文件名中的数字补位变成相同位数,使排序按数字的递增来排序
string[] infos1 = sFileName.Split(‘-‘); int n = infos1.Length; if (n > 1) { string[] infos2 = infos1[n - 1].Split(‘.‘); string num = infos2[0].PadLeft(4, ‘0‘); int i; string imagenamesuffix = ""; string imagenameprefix = ""; imagenamesuffix = num + ‘.‘ + infos2[1]; for (i = 0; i < n - 1; i++) { imagenameprefix += infos1[i] + ‘-‘; } string name = imagenameprefix + imagenamesuffix; sFileName = name; }
.Net 文件名补位
时间: 2024-10-05 02:57:10