strchr函数
来源:互联网 发布:gps定位系统平台源码 编辑:程序博客网 时间:2024/04/29 14:38
函数名称: strchr
函数原型: char* strchr(char* str,char ch);
函数功能: 找出str指向的字符串中第一次出现字符ch的位置
函数返回: 返回指向该位置的指针,如找不到,则返回空指针
参数说明: str-待搜索的字符串,ch-查找的字符
所属文件: <string.h>
#include <string.h>
#include <stdio.h>
int main()
{
char string[15];
char *ptr, c= 'r ';
strcpy(string, "This is a string ");
ptr=strchr(string, c);
if (ptr)
printf( "The character %c is at position: %d\n ",c,ptr-string);
else
printf( "The character was not found\n ");
return 0;
}
Parameter参数 Description描述 stringRequired. Specifies the string to search
必要参数。指定需要搜索的字符串searchRequired. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number
必要参数。指定搜索的对象。如果这个参数是一个数值,那么他将搜索与这个数值的ASCII值相匹配的字符
函数原型:
函数功能:
函数返回:
参数说明:
所属文件:
#include
#include
int
{
}
---------------------------------
1.函数的使用
The strchr() function searches for the first occurrence of a string inside another string.
strchr()函数的作用是:返回一个字符在另一个字符串中首次出现的位置到后者末尾的子字符串(大小写敏感)。
This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.
如果这个函数执行成功,将返回剩余字符串(存在相匹配的字符);如果没有找到相匹配的字符,则反会False。
This function is an alias of the strstr() function.
这个函数的功能与strstr()函数相类似。
必要参数。指定需要搜索的字符串searchRequired. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number
必要参数。指定搜索的对象。如果这个参数是一个数值,那么他将搜索与这个数值的ASCII值相匹配的字符
2.注意点
Note: This function is binary safe.
注意:strchr()函数是二进制精确[binary safe]的。
Note: This function is case-sensitive. For a case-insensitive search, use stristr().
注意:这个函数是区分字母大小写的。如果你想在不区分字母大小写的情况下进行搜索,那么可以使用stristr()函数。
3.使用举例1
函数名: strchr 功能: 在一个串中查找给定字符的第一个匹配之处\ 用 法: char *strchr(char *str, char c); 程序例: #include <string.h> #include <stdio.h> int main(void) { char string[15]; char *ptr, c = 'r'; strcpy(string, "This is a string"); ptr = strchr(string, c); if (ptr) printf("The character %c is at position: %d\n", c, ptr-string); else printf("The character was not found\n"); return 0; } 4.使用举例2: char buf[200]; int cur=m_prj.GetCurSel();//得到Combox控件当前的选项"工作调查|8|9" m_prj.GetLBText(cur,buf);//将当前选项的值赋给buf char *p,*q; q=strchr(buf,'|');//q为|8|9 memset(xmmc,0,sizeof(xmmc)); strncpy(xmmc,buf,q-buf);//q的地址减去buf的地址,得到“工作调查“ p=q; q++; q=strchr(q,'|');//q为"|9" memset(wjbh,0,sizeof(wjbh)); p++; strncpy(wjbh,p,q-p);//得到8 memset(xmbh,0,100); q++; strcpy(xmbh,q);//得到9
0 0
- strchr函数
- strchr() 函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr 函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- 函数strchr
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- linux之cut用法
- CSS样式覆盖规则
- Android用户首次打开APP出现教学蒙层效果的实现
- linux Shell ----mkdir和touch命令详解
- JAVA基础加强(四)
- strchr函数
- Android QQ登录
- VAX v10.9.2062.0-VAX Rebirth 1.0 分析 【转载请注明出处】
- select的理解
- nyoj题目60:谁获得了最高奖学金
- Android系统搜索对话框(浮动搜索框)的使用
- [android] SoundPool详解
- jsp学习
- 编程不能太局限,我们可以做的事情很多