这是我写的一个工作,它显示了3种比较字符串与区分大小写的不同方法。只需复制/粘贴/运行。
static void Job86(Args _args)
{
str a = 'Alex';
str b = 'aleX';
int i;
int n;
str c1, c2;
setPrefix("Compare");
for (n=1; n<=strLen(b); n++)
{
c1 = subStr(a, n, 1);
c2 = subStr(b, n, 1);
if (char2num(c1, 1) == char2num(c2, 1))
info(strFmt("Char2Num()\t%1 == %2", c1, c2));
else
info(strFmt("Char2Num()\t%1 != %2", c1, c2));
if (strCmp(c1, c2) == 0)
info(strfmt("strCmp()\t%1 == %2", c1, c2));
else
info(strFmt("strCmp()\t%1 != %2", c1, c2));
i = System.String::Compare(c1, c2);
if (i == 0)
info(strfmt("System.String::Compare()\t%1 == %2", c1, c2));
else
info(strFmt("System.String::Compare()\t%1 != %2", c1, c2));
}
}
这对于非字母数字字符不起作用。 更好的是测试差异小写:'char2num(testStr,i)!= char2num(strLwr(testStr),i)' –
感谢所有的hrlp! – ulisses
@ JanB.Kjeldsen - 哇!你的权利!我想到了数字,并使用str2IntOk()忽略它们,但没有考虑像“!”这样的符号。如果我理解正确,关键是测试NOT EQUALS,因为数字或符号的大写值与小写字母的值相同。如果您测试大写和小写值不相同,则您知道该字符是字母而不是数字或符号。感谢您指出! –