zoukankan      html  css  js  c++  java
  • 查找字符串(C++实现)

    查找字符串(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== '')
            return false;
        while(p != NULL)
        {
            //subStr 循环比较结束
            if(*q == '')
                return true;
            //srcStr 比 subStr 长度短
            if(*p =='')
                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 0;
    }
  • 相关阅读:
    AUTOSAR-文档阅读
    前端 html
    http协议
    python格式化输出
    IO模型
    协程函数
    伟大的GIL
    苑之歌(进程,线程)
    python之模块导入和包
    任性计算器
  • 原文地址:https://www.cnblogs.com/JczmDeveloper/p/3365382.html
Copyright © 2011-2022 走看看