strstr查找字符串, strch查找字符 (在字符串中) [Microsoft Corporation]
2011-08-26 10:57
211 查看
/*** *char *strchr(string, c) - search a string for a character * *Purpose: * Searches a string for a given character, which may be the * null character '\0'. * *Entry: * char *string - string to search in * char c - character to search for * *Exit: * returns pointer to the first occurence of c in string * returns NULL if c does not occur in string * *Exceptions: * *******************************************************************************/ char * __cdecl strchr ( const char * string, int ch ) { while (*string && *string != (char)ch) string++; if (*string == (char)ch) return((char *)string); return(NULL); }
/****char *strstr(string1, string2) - search for string2 in string1**Purpose:* finds the first occurrence of string2 in string1**Entry:* char *string1 - string to search in* char *string2 - string to search for**Exit:* returns a pointer to the first occurrence of string2 in* string1, or NULL if string2 does not occur in string1**Uses:**Exceptions:********************************************************************************/char * __cdecl strstr (const char * str1,const char * str2){char *cp = (char *) str1;char *s1, *s2;if ( !*str2 )return((char *)str1);while (*cp){s1 = cp;s2 = (char *) str2;while ( *s1 && *s2 && !(*s1-*s2) )s1++, s2++;if (!*s2)return(cp);cp++;}return(NULL);}
相关文章推荐
- php strstr查找字符串中是否包含某些字符的查找函数
- 字符串比较函数strncasecmp():比较字符串的前n个字符|字符串查找函数strstr和string.find() 查找字符串str1中是否存在与str2一样的子字符串
- C语言字符与字符串查找函数strstr、wcsstr(wcswcs)、_tcsstr
- php strstr查找字符串中是否包含某些字符的查找函数
- php strstr查找字符串中是否包含某些字符的查找函数
- 查找字符串中第一个只出现一次的字符
- 查找字符串中字符不重复的最大子串(C/C++)
- ASP.NET正则表达式查找字符串中重复的字符
- C语言面试题:查找字符串中第一个不重复的字符
- 字符串-01. 在字符串中查找指定字符
- 查找输入字符串中第一个相同的字符,并显示该字符
- 字符串/字符匹配:strstr()及strchr()函数
- strdup字符复制,strtok_r分割字符串,strchr查找字符等的用法
- PHP检索字符串(strstr)文件上传查找指定(.jpg)文件
- 记录一次查找字符串中多个相同字符,并设置指定大小显示
- 字符串-01. 在字符串中查找指定字符
- 查找字符串中出现最多的字符和个数(两种方法一个普通方法 一个是正则表达式方式)
- js 判断字符串是否包含某字符串,String对象中查找子字符indexOf,查找字符串出现的次数split
- 在不用strstr()函数的情况下在字符串中查找某一子字符串