Questions tagged [strstr]

A function that searches a string in another string.

A function that searches a string in another string.

Examples

php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

(Example taken from php.net)

Resources

363 questions
6
votes
2 answers

strcmp implementation not working with special characters

I'm trying to implement my own strcmp function, my strcmp bahaves differently when I use special characters. #include int my_strcmp(const char *s1, const char *s2) { const char *str1; const char *str2; str1 = s1; …
Junius L
  • 15,881
  • 6
  • 52
  • 96
6
votes
3 answers

strstr() function

I am trying to write a program that compares a substring that the user enters with an array of strings. #include #include char animals[][20] = { "dogs are cool", "frogs are freaky", "monkeys are crazy" }; int…
tenkii
  • 449
  • 2
  • 10
  • 23
5
votes
5 answers

How to check if a word exists in a sentence

For example, if my sentence is $sent = 'how are you'; and if I search for $key = 'ho' using strstr($sent, $key) it will return true because my sentence has ho in it. What I'm looking for is a way to return true if I only search for how, are or you.…
Tafu
  • 53
  • 1
  • 1
  • 5
5
votes
2 answers

strstr not functioning

Why does this particular piece of code return false on the strstr() if I input "test"? char input[100]; int main() { fgets(input, 100, stdin); printf("%s", input); if(strstr("test message", input)) { printf("strstr…
KWJ2104
  • 1,959
  • 6
  • 38
  • 53
5
votes
4 answers

Efficient way to split a vector of a full name in to 2 separate vectors

I have a vector consisting of full names with the first and last name separated by a comma this is what the first few elements look like: > head(val.vec) [1] "Aabye,ֲ Edgar" "Aaltonen,ֲ Arvo" "Aaltonen,ֲ Paavo" [4] "Aalvik Grimsb,ֲ…
Lee
  • 129
  • 2
  • 7
5
votes
1 answer

Does strstr()'s implementation in gcc and VS have linear complexity?

I know that there are fast string search algorithms, like Boyer–Moore and Knuth–Morris–Pratt, that have O(n+m) complexity, while the trivial solution would be O(n*m). So does the implementation of strstr() for the most popular toolchains - gcc and…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
5
votes
3 answers

Opposite PHP function of strstr to return first part of string, not last

I have an string, something like this: $abcdef(+$1.00) I'm trying to get the first part of the string before the first parenthesis: $abcdef Currently if I use strstr() it will return the part of the string after the specified character: $newstr…
bobbiloo
  • 422
  • 5
  • 22
4
votes
3 answers

Converting a C (\0 terminated) string to a PHP string

PHP is one of those languages I use periodically, but usually have to dust the cobwebs off when I start using it again. The same applies this week whilst I port some C code to PHP. This uses a lot of AES encryption and SHA256 hashing - all working…
winwaed
  • 7,645
  • 6
  • 36
  • 81
4
votes
2 answers

Applying strstr() multiple times on same string in C

I'm trying to write a code that extracts all words/strings between the and tags using strstr. But it seems that it just gets stuck to the first string extracted, which is "quick". How can I get the code to keep going after extracting the first…
4
votes
4 answers

PHP strstr - The reverse method

I'm looking to get the same exact results as php strstr command (while it set to true) but in reverse order. I know that I can simply reverse the string and use strstr and then reverse it again but I was wonder if there is any internal php command…
Steven
  • 249
  • 5
  • 14
4
votes
1 answer

Weird strstr behaviour

i'm trying to find the position of substring in a string. #include #include void find_str(char const* str, char const* substr) { char* pos = strstr(str, substr); if(pos) { printf("found the string '%s' in '%s'…
Can Vural
  • 2,222
  • 1
  • 28
  • 43
4
votes
1 answer

Using strstr in C

This program is not giving any output... the function find_track should return the track if a matching string is entered to it. #include #include char tracks[][80] = { "I left my heart in Harward Med School", "Newark,…
user2035503
4
votes
4 answers

How to find the first occurrence of one of several characters (other than using regex)

After going through a bunch of threads, I know that I need to use regex.h for using regular expressions in C & C++. But I was wondering, is there an easier way to search for occurrence of "/" or "\" in a string. // I have a strstr statement like…
sskanitk
  • 475
  • 4
  • 11
  • 19
3
votes
1 answer

strstr: behavior different using different versions of gcc

I'm porting a program that works with Ubuntu 8.04 (gcc version 4.2.4) to 10.04 (gcc version 4.4.3). I have the following code: #include #include int main(void) { char p[100] = "////abcd"; char *t; /* Remove duplicate…
Johan
  • 5,003
  • 3
  • 36
  • 50
3
votes
3 answers

wrong parameter count for strstr()

I have built a nav menu in wordpres using a posts GUID, and post title, I am taking only part of the title and to do this I am doing the following, $casestudylist .= "
Udders
  • 6,914
  • 24
  • 102
  • 194
1
2
3
24 25