c - 使用 'srtchr()' 搜索子串

标签 c string substring string-search strchr

使用函数 strchr 是否可以在字符串中搜索 substring 而不是 character

示例:

而不是这个:

int r=strchr("Hello World",'W');

这个可以用吗:

int r=strchr("Hello World","World");

最佳答案

Using the function 'strchr()' is it possible to search for a 'substring' in a string instead of a 'character'?

Example :

Instead of this : int r=strchr("Hello World",'W');

Can this be used : int r=strchr("Hello World","World");

不,那是strstr() is for .

另请注意 strchr()不返回 int,它返回指向所搜索字符的 char * 指针,如果未找到则返回 NULL。存在编译器警告是有原因的...

关于c - 使用 'srtchr()' 搜索子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47773154/

相关文章:

C、从字符串中获取想要的元素

sql - 获取SQL中前2个特殊字符之间的字符

php - 数组和子字符串 PHP

c - 调用 "getpid() == fork()"时应该返回什么

c - 用 C 将结构写入和读取到文件中

c - 在 Linux 中使用文件时,哪些内核模块负责?

excel - 从另一个单元格中减去一个单元格中的字符串,这些字符串在excel中以逗号分隔

objective-c - 在大型 NSString 中有效地找到许多关键字中的第一个

c - 从C中的字符串中获取子字符串

string - Bash 将输出解析为变量