请问:如何让CString::Find(),查找字符或字符窜时不区分大小写?

kucao 2003-03-11 08:49:21
例如:CString str = "<INUPT Name = "XxX">";
str.Find("inupt")时查不到"INUPT";
当然这只是个例子,我可能会查任何一个字符串,如:str.Find("NAME");
str.Find("xxx");
请问又什么办法让CString::Find()不区分大小写。我的CString是不固定的"*.htm"文件。
谢谢!!
...全文
2876 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kucao 2003-03-13
  • 打赏
  • 举报
回复
谢了!
结贴!
marconow 2003-03-12
  • 打赏
  • 举报
回复
CStringT::CompareNoCaseSee Also
CStringT Overview | Class Members
Compares two strings (case insensitive).

int CompareNoCase(
PCXSTR psz
) const throw();
Parameter
psz
The other string used for comparison.
Return Value
Zero if the strings are identical (ignoring case), <0 if this CStringT object is less than psz (ignoring case), or >0 if this CStringT object is greater than psz (ignoring case).

Remarks
The generic-text function _tcsicmp, which is defined in TCHAR.H, maps to either _stricmp, _wcsicmp or _mbsicmp depending on the character set that is defined at compile time. Each of these functions performs a case-insensitive comparison of the strings, and is not affected by locale. For more information, see _stricmp, _wcsicmp, _mbsicmp in the Run-Time Library Reference.

Example
The following example demonstrates the use of CStringT::CompareNoCase.

//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;

CAtlString s1( "abc" );
CAtlString s2( "ABD" );
_ASSERT( s1.CompareNoCase( s2 ) < 0 ); // Compare with a CAtlString.
_ASSERT( s1.CompareNoCase( "ABE" ) < 0 ); // Compare with LPTSTR string.
See Also
CStringT Overview | Class Members



--------------------------------------------------------------------------------

Send feedback to Microsoft

© 2001 Microsoft Corporation. All rights reserved.
marconow 2003-03-12
  • 打赏
  • 举报
回复
给你介绍一个函数:
CString::CompareNoCase
用MSDN查查,字符串比较的。
或许对你有点启发
changbaohua 2003-03-12
  • 打赏
  • 举报
回复

int nPos = str.FindOneOf("IiNn");
switch (str[nPos]) {
case 'I':
case 'i':
取5个字节,转成小写,看是否=="input";
case 'N':
case 'n':
.......
}
kucao 2003-03-12
  • 打赏
  • 举报
回复
楼上两位可能没听明白我的意思:
<input name=>或<INPUT NAME=>或<Input Name=>在浏览器中解释是同样的,无所谓区不区分大小写。但我要的是<input name="XxX">中的"XxX",这个值我要在其他程序中调用,如:Jsp中:XxX != XXX != xxx;我无法直接取得"XxX",所以我只能先查"<input" 和 "name=",然后再找"XxX",而我用str.Find("inupt")时查不到页中的"INUPT";用str.Find("INPUT")时查不到页中的"input";还有一些"<Input" 或 "Name" 之类的。
请大家想想办法!
感谢以上所有兄台的回答!
还有没有其他方法?
谢谢!!
DoubleJiang 2003-03-12
  • 打赏
  • 举报
回复
同意: ydtj829(按程序做事)
但是会较慢,使用小字串可以
ydtj829 2003-03-12
  • 打赏
  • 举报
回复
如果需要使用原文件,那么为什么不区分大小写呢?如果不要区分大小写,为什么还要使用原文件呢?
xyw2278 2003-03-11
  • 打赏
  • 举报
回复
先将原来的字符串保存一下不就得了
changbaohua 2003-03-11
  • 打赏
  • 举报
回复
"XxX"也用tempstring.MakeUpper(),然后up;
sunyt 2003-03-11
  • 打赏
  • 举报
回复
你先 CString strTmp = strname;
strTmp.MakeUpper;
int nPos = strTmp.Find("XXX");
strname = strname.left(nPos);
kucao 2003-03-11
  • 打赏
  • 举报
回复
ydtj829(按程序做事)兄:
我最终目的不是find("input")或find("name"),而是要name = "XxX" 中的 "XxX";
我要在程序中用 "XxX",不可以将"XxX"转为 "xxx" 或 "XXX" ;

lanzhengpeng2(兰征鹏)兄:
可否写几句详细的?

谢谢两位!
skyzxg 2003-03-11
  • 打赏
  • 举报
回复
如上所示
ydtj829 2003-03-11
  • 打赏
  • 举报
回复
很简单,你先把str.MakeUpper()(或lower)使用一下,然后在那么find("INPUT")(或input)如何?假如有汉字就不行了。。。。。
lanzhengpeng2 2003-03-11
  • 打赏
  • 举报
回复
没有必要死揪着CString不放,使用其他函数如strstr试试

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧