判断 一个字符串中 是否有 指定字符

herman011 2008-07-02 09:32:57
string a="ACCGTAGCTACGAT";

if(a )


怎么判断string a里面不存在'N'这个字符 ,

如果没有N 这个字符 上述 if 里面的为真 。 一旦碰到有 N 就 假


if 里面怎么写?
...全文
64 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
那个天真的人 2008-07-02
  • 打赏
  • 举报
回复
if(strchr(a,“N”)==NULL)
Gob00st 2008-07-02
  • 打赏
  • 举报
回复
不用count,用string内置函数即可

int main(void)
{
string a="ACCGTAGCTACGANT";
if(a.find_first_of("N")!=string::npos)
{
cout<<"find N"<<endl;
}
return 0;
}
free1879 2008-07-02
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>
using namespace std;
int main()
{
string a("ACCGTAGCTACGAT);
for (string::size_type ix = 0; ix != a.size(); ++ix) {
if (a[ix] == 'N')
cout << "N at:" << ix << endl;
else
cout << "N not exists!" << endl;
}
return 0;
}
herman011 2008-07-02
  • 打赏
  • 举报
回复
楼上:

317 D:\SRMAP\MapNext.cpp no matching function for call to `strstr(std::string&, char)'


我的 是 string 类型的
string a="ACCGTAGCTACGAT";

K行天下 2008-07-02
  • 打赏
  • 举报
回复
string
的 find方法!
xabcxyz 2008-07-02
  • 打赏
  • 举报
回复
if(strstr(a,“N”)==NULL)
herman011 2008-07-02
  • 打赏
  • 举报
回复
有 内置的 函数功能吗?


比如像 count(a.begin(), a.end(), 'N')>0

不过 这么慢了点 。。。 要记数。。。。

起码 比 count(a.begin(), a.end(), 'N')>0 这个 快 的 判断 有没有 就行了

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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