今天研究了下,发现windows资源管理器中的排序方式非常奇葩(按文件名) 中文的没有看,英文的规则是这样的将连续的数字当成一个值来比较,比如 1 ,2,10,3的排序方式1,2,3,10如果 是a1,a2,a10那么还是a1,a2,a10 如果连续数字对应的值相同则按照以下规则长度大的排在前 (小于长度小的)例如 010=10所以010 排在10前面 下面给出windows资源管理器中的排序所对应的比较函数 int compare(CString str1,CString str2)
{int i,j;i=0;j=0;string temp1,temp2;int num1,num2;
int length=min(str1.GetLength(),str2.GetLength());
 while(i<length&&j<length)
             { temp1.clear();temp2.clear();
     if(str1.GetAt(i)>'9'||str1.GetAt(i)<'0'||str2.GetAt(j)>'9'||str2.GetAt(j)<'0')
                   {
        if(str1.GetAt(i)==str2.GetAt(j)){i++;j++;continue;}
       else if(str1.GetAt(i)>str2.GetAt(j))return 1;
       else return -1;
                    }
        while(str1.GetAt(i)<='9'&&str1.GetAt(i)>='0'){temp1+=str1.GetAt(i);i++;}
        while(str2.GetAt(j)<='9'&&str2.GetAt(j)>='0'){temp2+=str2.GetAt(j);j++;}
        num1=atoi(temp1.c_str());num2=atoi(temp2.c_str());
     if(num1==num2){
               if(temp1.length()<temp2.length())return 1;
               else if(temp1.length()>temp2.length())return -1;
               else continue;
                 }
        else if(num1>num2)return 1;
     else return -1;   
            } return (str1.GetLength()>str2.GetLength())?1:-1; } 有了这个,排序就很容易了 以上算法在window下验证过,准确无误(但不包括中文字符)有关中文字符的部分,有兴趣的同学可以继续研究

解决方案 »

  1.   

    还是版主见多识广啊,楼主有心了
      

  2.   

    中文字符是两个的,值大于128,但是具体它是按什么顺序排列就不知道了,关注中
    知道的给指教一下
      

  3.   

    好像在不同机器上会有不同的排序方式,不知道是为什么。
      

  4.   

    您好
    我是本版版主
    此帖已多日无人关注
    请您及时结帖
    如您认为问题没有解决可按无满意结帖处理
    另外本版设置了疑难问题汇总帖
    并已在版面置顶
    相关规定其帖子中有说明
    您可以根据规定提交您帖子的链接
    如您目前不想结帖只需回帖说明
    我们会删除此结帖通知见此回复三日内无回应
    我们将强制结帖
    相关规定详见界面界面版关于版主结帖工作的具体办法