C string strchr() 函数
定义和用法
strchr() 函数返回一个指向字符串中首次出现的字符位置的指针。
strchr() 函数定义在 <string.h> 头文件中。
注意:要查找字符串中最后一次出现的字符,请使用 strrchr() 函数。
实例
获取字符串中首次出现的字符的指针:
char myStr[] = "Hello World";
char *myPtr = strchr(myStr, 'W');
if (myPtr != NULL) {
printf("%s", myPtr);
}
语法
strchr(char * str, int character);
参数
| 参数 | 描述 |
|---|---|
| str | 必需。指向要搜索的字符串的指针。 |
| character | 必需。要搜索的字符。也可以使用字符的 ASCII 值。 |
技术细节
| 返回: |
返回 如果未找到该字符,则返回 NULL。 |
|---|
相关页面
教程:C 字符串
教程:C 字符串函数