1

次のような文字列が含まれている場合、どのように文字列を一致させることができるのでしょうか"Just"str1str1

"this is Just/1.1.249.4021 a test" 
// "Just" will always be the same

を使用して一致させようとしてstrstrいますが、これまでのところ、/...

それを一致させる方法について何か提案はありますか?ありがとう

4

3 に答える 3

2

これは私にとってはうまくいきます - あなたはどうですか?

#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);
}
于 2010-03-30T03:46:52.733 に答える
1

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));
于 2010-03-30T03:47:17.150 に答える
-1

strstr文字列が実際に "Just/1.1.249.4021" の場合、大文字と小文字が区別されるため、"just" を見つけることができません。大文字と小文字を区別しないバージョンが必要な場合は、独自のバージョンを作成するか、既存の実装用にGoogleを作成する必要があります。

于 2010-03-30T03:51:27.443 に答える