C语言判断某个字符串中 是否存在子字符串
生活随笔
收集整理的這篇文章主要介紹了
C语言判断某个字符串中 是否存在子字符串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
直接上code
char *p="add@/devices/platform/0.soc/xxx.dwmmc1/mmc_host/mmc1/mmc1";char str[128] = "add@/devices/platform/0.soc/xxx.dwmmc1/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p1 ACTION=add DEVPATH=xxxxx";if(strstr(str,p)){printf("p:%s\n",p);}或者如下寫法也是可以的const char src[20] = "test12345";const char content[10] = "12";char *ret;ret = strstr(src, content);if (ret == NULL) {printf("子字符串沒找到\n");} else {printf("子字符串是: %s\n", ret);}運行結果: $ gcc -o test test.c $ ./test 子字符串是: 12345總結
以上是生活随笔為你收集整理的C语言判断某个字符串中 是否存在子字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于jsp中 对只转发结果集的无效操作:
- 下一篇: 成功原来这样简单