社区
C语言
帖子详情
请问在std::string中如何compareNoCase?
tlovexyj
2002-04-23 09:46:47
使用string时,发现只有compare,如果要compareNoCase,应该如何?
...全文
1043
6
打赏
收藏
请问在std::string中如何compareNoCase?
使用string时,发现只有compare,如果要compareNoCase,应该如何?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
babysloth
2002-04-23
打赏
举报
回复
string的字符大小比较功能都来自第2个(char_traits)模板参数,anrxhzh(百宝箱)给出的那个地址,是The C++ Standard Library的作者Josuttis提的方法,个人感觉非常好。
tlovexyj
2002-04-23
打赏
举报
回复
也就是说string并无实现CompareNoCase。
小弟意思是怕自己孤漏寡闻,窃以为楼上的兄台的实现比较cool。
放一放,晚上给分。
谢谢各位大虾。
pathe
2002-04-23
打赏
举报
回复
就是就是
using namespace std;
class NoCase
{
public:
static bool compare(const wstring& x, const wstring& y);
};
bool NoCase::compare (const wstring& x, const wstring& y)
{
wstring::const_iterator p = x.begin();
wstring::const_iterator q = y.begin();
while (p != x.end() && q != y.end() && toupper(*p) == toupper(*q))
{
++p;
++q;
}
if (p == x.end())
{
return (q == y.end());
}
if (q == y.end())
{
return false;
}
return (toupper(*p) < toupper(*q));
}
huangwu007
2002-04-23
打赏
举报
回复
自己做一个忽略大小写的函数不就可以了,方法如 Nepton(小牛牛) :-)
Nepton
2002-04-23
打赏
举报
回复
1.让两个字符串全大写
2.比较
anrxhzh
2002-04-23
打赏
举报
回复
http://www.josuttis.com/libbook/string/icstring.hpp.html
使用
std
::equal()为
string
不区分大小写进行对比
在MFC的C
String
中
有
Compare
No
Case
()接口可以方便的不区分大小写对比字符串,但
std
::
string
却没有,但可以使用
std
::equal()对比是否相同: #include <iostream> #include <vector> #include <algorithm> #include <sstream> #include...
c++,
string
,
compare
,no
case
,for copy
总结:如何在c++
中
进行大小写忽略的比较,基于
std
:
string
ref1,ref2,ref3 问题由来: 标准字符 (typedef basic_
string
string
)由于国际化过程
中
,没有实现每一种语言的大小写转换函数,也没要提供基于ansi字符的大小写忽略比较。 解决方案1:先转换大小写再比较 策略1.
std
method
c++
中
不区分大小写比较字符串大小
#include using namespace
std
; //
string
转小写
std
::
string
JGUtil::strToLower(
std
::
string
str) {
std
::
string
strTmp = str; transform(strTmp.begin(), strTmp.end(), strTmp.b
C++:
Compare
No
Case
函数
在C++
中
,
Compare
No
Case
函数通常用于比较两个字符串(
string
)是否相等,而不考虑它们的大小写。它是一个非常常用的函数,尤其在需要进行字符串比较时。
C++不区分大小写比较
string
类似C
String
.
compare
No
Case
使用transform();全转化为小写,然后对比
string
#include<
string
>#include<algorithm>usingnamespace
std
;namespaceBaseFunc{//
string
转小写
string
strToLower(const
string
&str){
string
s...
C语言
69,370
社区成员
243,082
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章