我们最熟悉的字符串比较函数莫过于strcmp了,但这个函数仅仅是根据字符进行比较,没有考虑字符串的逻辑意义,为此微软为我们提供了一个StrCmpLogicalW函数,它比较数字时不将其视为文本而是视为数值。 我们可以从下列这个简单的字符串数组排序的结果看出这两个函数的区别: 使用StrCmpLogicalW进行比较的结果: 2string3string20stringst2ringst3ringst20ringstring2string3string20 使用简单的strcmp函数进行比较的结果: 20string2string3stringst20ringst2ringst3ringstring2string20string3 下面这段代码就是模仿这个函数的实现: #include <iostream>#include <afx.h>#include "deelx.h"using namespace std;#define MATCH_NUMBERS "[+-]?\\d+(\\.\\d+)?" int Compare(CString csText1, CString csText2) 代码中使用了一个开源的正则表达式引擎,DEELX 正则表达式引擎, 相关文章: 2022-12-23 2022-12-23 2022-12-23 2022-12-23 2021-11-27 2021-08-12 2022-12-23 2022-03-12