查找字符串(C++实现),不使用库函数:

// SubString.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
using namespace std; bool FindSubString(char* srcStr,char* subStr)
{
char* p = srcStr;
char* q = subStr;
if(p ==NULL || *p== '\0')
return false;
while(p != NULL)
{
//subStr 循环比较结束
if(*q == '\0')
return true;
//srcStr 比 subStr 长度短
if(*p =='\0')
return false;
if(*p != *q)
{
p ++;
q = subStr;
}
else
{
p ++;
q ++;
}
}
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
char srcStr[] = "Kobe Bean Bryant, nicknamed the '小飞侠', is an American professional basketball player for the Los Angeles Lakers of the National Basketball Association";
char subStr[] = "Bryant";
if(FindSubString(srcStr,subStr))
cout <<"I find substring" <<endl;
else
cout <<"I do not find substring" << endl;
cin.get();
return ;
}

查找字符串(C++实现)的更多相关文章

  1. 在文件夹中 的指定类型文件中 查找字符串(CodeBlocks+GCC编译,控制台程序,仅能在Windows上运行)

    说明: 程序使用 io.h 中的 _findfirst 和 _findnext 函数遍历文件夹,故而程序只能在 Windows 下使用. 程序遍历当前文件夹,对其中的文件夹执行递归遍历.同时检查遍历到 ...

  2. php查找字符串首次出现的位置 判断字符串是否在另一个字符串中

    strpos - 查找字符串首次出现的位置 说明 int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) 返回 nee ...

  3. 查找字符串的 KMP 算法

    查找字符串是我们平常编程过程中经常遇到的,现在介绍一种查找字符串算法,增加程序的执行速度. 通常我们是这么写的: /* content: search a string in a othor stri ...

  4. 回朔法/KMP算法-查找字符串

    回朔法:在字符串查找的时候最容易想到的是暴力查找,也就是回朔法.其思路是将要寻找的串的每个字符取出,然后按顺序在源串中查找,如果找到则返回true,否则源串索引向后移动一位,再重复查找,直到找到返回t ...

  5. Lua查找字符串注意

    问题: 使用Lua写Wireshark插件时,经常匹配字符串.今天使用string.find()函数查找字符串”max-age”,没有找到. 分析: local index = string.find ...

  6. Javascript 查找字符串中出现最多的字符和出现的次数

    <script type="text/javascript"> //查找字符串中出现最多的字符和出现的次数 var str = 'Thatwheneying its o ...

  7. php查找字符串是否存在

    strstr //搜索字符串在另一字符串中的首次出现(对大小写敏感) //该函数返回字符串的其余部分(从匹配点).如未找到则返回 false stristr //查找字符串在另一字符串中第一次出现的位 ...

  8. linux上查找文件存放地点和文件中查找字符串方法

    一.查找文件存放地点 1.locate 语法:locate <filename> locate命令实际是"find -name"的另一种写法,但是查找方式跟find不同 ...

  9. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words

    1.1       字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...

随机推荐

  1. FFMPEG之TimeBase成员理解

    http://blog.csdn.net/supermanwg/article/details/14521869

  2. VC提交网页表单(一共八篇)

    VC提交网页表单-自动评论留言(1)http://blog.csdn.net/wangningyu/article/details/4526357VC提交网页表单-自动评论留言(2)http://bl ...

  3. webview调用javascript脚本无反应

    最近遇到一个问题:在html中有一段javascript脚本定义了一个方法,在使用webview.loadUrl("javascript:方法名()")时方法未执行,后来 查资料发 ...

  4. [LeetCode#218] The Skyline Problem

    Problem: A city's skyline is the outer contour of the silhouette formed by all the buildings in that ...

  5. EasyUI的增删查改(后台ASP.NET)

    转自:http://www.cnblogs.com/dedeyi/archive/2013/04/22/3035057.html 某某人曾经跟我说,你们做系统不就是增删查改吗. 是啊,很多时候我们就是 ...

  6. loadrunner调用plink,远程linux执行shell命令

    loadrunner调用plink,远程linux执行shell命令   脚本: Action() {   char* cmd; cmd = lr_eval_string("C:\\\&qu ...

  7. EF中使用存储过程

    1.存储过程使用out参数返回结果 存储过程: create or replace procedure PROC_GETSEQ(tbname varchar,ReturnNum out number) ...

  8. time.h

    目录 1简介 2代码示例 3从系统时钟获取时间方式 4time函数介绍 函数名称: localtime 函数名称: asctime 函数名称: ctime 函数名称: difftime 函数名称: g ...

  9. JSP页面同时操作所有Input输入框

    项目里要写个function,对页面上所有input输入框进行非空判断,对非空input全部置为readOnly,提交的时候判断是否有空白项目. var inputs=document.getElem ...

  10. SWFUpload无刷新文件批量上传

    一.首先将SWFUpload所有文件加入项目中,如图