在字符串中查找字符串 急急C語言查找子字符串?
急急C語言查找子字符串?使用strstrstrstr函數(shù)包含file:string。H函數(shù)名:strstrstrstr函數(shù)原型:external char*strstrstr(char*STR1,ch
急急C語言查找子字符串?
使用strstrstrstr函數(shù)
包含file:string。H
函數(shù)名:strstrstrstr
函數(shù)原型:external char*strstrstr(char*STR1,char*STR2)
函數(shù):查找STR1字符串中STR2字符串的第一個(gè)位置(STR2的字符串終止符除外)。
返回值:返回該位置的指針,如果找不到,則返回空指針。
源代碼:
#include
#include
void main(){
char ch1[255]=“ABCDE”
char CH2[100]=“CD”
char*ch//用于接受返回值
if((ch=strstrstrstr(ch1,CH2))==null){//表示沒有要查找的字符串
printf(“-1n”)
else{//表示找到字符串
printf(%dn“,ch-ch1 1)//CDE地址減去ABCDE 1地址
}}}
怎么在string字符串中查找一個(gè)特定的字符串?
看看API。類stringindexof(string STR)返回字符串中第一個(gè)指定子字符串的索引。如果關(guān)鍵字存在于字符串中,則從位0開始返回偏移量(即索引)