次のような文字列が含まれている場合、どのように文字列を一致させることができるのでしょうか"Just"
。str1
str1
"this is Just/1.1.249.4021 a test"
// "Just" will always be the same
を使用して一致させようとしてstrstr
いますが、これまでのところ、/...
それを一致させる方法について何か提案はありますか?ありがとう
これは私にとってはうまくいきます - あなたはどうですか?
#include <string.h>
#include <stdio.h>
int main(void)
{
char haystack[] = "this is just\2323 a test";
char needle[] = "just";
char *loc = strstr(haystack, needle);
if (loc == 0)
printf("Did not find <<%s>> in <<%s>>\n", needle, haystack);
else
printf("Found <<%s>> in <<%s> at <<%s>>\n", needle, haystack, loc);
return(0);
}
strstr() の使用方法に何か問題があるに違いありません。次のコードは問題なく動作します...
const char *s = "this is just\2323 a test";
char *p = strstr(s, "just");
if(p)
printf("Found 'just' at index %d\n", (int)(p - s));
strstr
文字列が実際に "Just/1.1.249.4021" の場合、大文字と小文字が区別されるため、"just" を見つけることができません。大文字と小文字を区別しないバージョンが必要な場合は、独自のバージョンを作成するか、既存の実装用にGoogleを作成する必要があります。