功能:查找第二个字符串是否存在第一个字符串中。

输入:字符串1,字符串2

返回值:成功返回str1中的位置,失败返回NULL

#include <iostream>
using namespace std;
char *_strstr(const char *str1,const char *str2)
{
int n;
if (*str2)
{
while(*str1)
{
for (n = 0;*(str1 + n) == *(str2 + n);n++)
{
if (!*(str2 +n +1))
{
return (char*)str1;
}
}
str1++;
}
return NULL;
}
else
return (char*) str1;
}
int main()
{
const char *str1 = "abcdef";
const char *str2 = "de";
cout << _strstr(str1,str2)<<endl;
return 0;
};

字符串之strstr的更多相关文章

  1. C 语言 字符串命令 strstr()的用法 实现将原字符串以分割串分割输出

    C 语言 字符串命令 strstr()的用法 实现将原字符串以分割串分割输出 strstr() 命令是在原字符串中查找指定的字符串第一次出现的地址,用这个特性可以实现字符的分割,判断是否包涵等功能: ...

  2. 字符串查找 strstr

     strstr函数  分类: LINUX 函数名: strstr 功 能: 在串中查找指定字符串的第一次出现 用 法: char *strstr(char *str1, char *str2); st ...

  3. 实现字符串检索strstr函数、字符串长度strlen函数、字符串拷贝strcpy函数

    #include <stdio.h> #include <stdlib.h> #include <string.h> /* _Check_return_ _Ret_ ...

  4. 使用PHP的strstr()函数来统计一段字符串中元音字母的个数(区分大小写)

    <?php/**练习:统计一段字符串中所有元音字母的个数(区分大小写)*/$str='This is a test file.'; //原始字符串echo $str.'<br>'; ...

  5. C语言-字符串函数的实现(五)之strstr

    C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...

  6. [PHP源码阅读]strpos、strstr和stripos、stristr函数

    我在github有对PHP源码更详细的注解.感兴趣的可以围观一下,给个star.PHP5.4源码注解.可以通过commit记录查看已添加的注解. strpos mixed strpos ( strin ...

  7. 前端学PHP之字符串函数

    × 目录 [1]特点 [2]输出 [3]空格[4]大小写[5]HTML[6]格式化[7]比较 前面的话 字符串的处理和分析在任何编程语言中都是一个重要的基础,往往是简单而重要的.信息的分类.解析.存储 ...

  8. PHP常用字符串的操作函数

    字符串转换类函数 addcslashes函数:以C语言风格使用反斜线转义字符串中的字符 addslashes函数:使用反斜线引用字符串 chop函数:清除字符串中的连续空格 get_html_tran ...

  9. PHP字符串处理

    /*1 字符串格式化 */ $str = ' php '; //清理两边的空格trim();,左边ltrim(); 边rtrin() echo trim($str); //nl2br();将换行符\n ...

随机推荐

  1. sublime text 3 修改侧边栏字体

    安装PackageResourceViewer快捷键 Ctrl+Shift+P 打开 Command Palette 输入 Package Control:Install 回车, 等待加载packag ...

  2. Atitit.异常机制的设计原理

    Atitit.异常机制的设计原理 缺陷 关键是只要知晓有一个异常表的存在,try 的范围就是体现在异常表行记录的起点和终点.JVM 在 try 住的代码区间内如有异常抛出的话,就会在当前栈桢的异常表中 ...

  3. 203. Remove Linked List Elements【easy】

    203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...

  4. 219. Contains Duplicate II【easy】

    219. Contains Duplicate II[easy] Given an array of integers and an integer k, find out whether there ...

  5. docker的使用02

    自定义容器名称: docker run --name -i -t ubuntu /bin/bash docker ps -a 数据卷的使用 数据卷其实就是容器和宿主机目录之间的映射. 具体实现: su ...

  6. java - day15 - NonameInner

    匿名内部类 public interface Inter {} interface Inter2{ void show(); } main(){ //错误,接口不能实例化 Inter t = new ...

  7. WebMethod Session

    [WebMethod(EnableSession = true)] public static string SayHello() { LxUserContext depno = HttpContex ...

  8. Spring MVC Hibernate验证器

    下面的示例演示如何使用Spring Web MVC框架在表单中使用错误处理和验证器. 首先使用Eclipse IDE,并按照以下步骤使用Spring Web Framework开发基于动态表单的Web ...

  9. 用记事本写的java程序引用jar文件

    1.将须要用的jar文件和java程序复制到同一个文件文件夹下 2.进行编译.编译的命令:javac -cp log4j-1.2.15.jar A.java 3.进行运行.运行的命令:java -cp ...

  10. CentOS 6.5 Ruby源码安装

    清除旧版Ruby,若存在 yum remove ruby 若为源码,使用如下命令 cd <your-ruby-source-path> make uninstall 下面开始安装Ruby ...