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
3
votes
4 answers

Code to find strings in source code over many urls

I want to enter a very long list of urls and search for specific strings within the source code, outputting a list of urls that contain the string. Sounds simple enough right? I have come up with the bellow code, the input being a html form. You can…
user586011
  • 1,908
  • 4
  • 18
  • 29
3
votes
3 answers

Matching an exact word using in c

Can I use the strstr function to match exact word? For example, let's say I have the word hello, and an input string line: if char* line = "hellodarkness my old friend"; and I use result = strstr(line, "hello"); result will match (be not NULL),…
A. Wali
  • 454
  • 3
  • 22
3
votes
4 answers

strstr() equivalent in C#

I have two byte[] and I want to find the first occurrence of the second byte[] in the first byte[] (or a range in it). I don't want to use strings for efficiency (translating the first byte[] to a string will be inefficient). Basically I believe…
brickner
  • 6,595
  • 3
  • 41
  • 54
3
votes
1 answer

strstr to show string before occurance

I want to get the first bit of the string after the occurrence of the needle like this... $user = strstr('someemail@yahoo.com', '@', true); But this only works with PHP Version 5.3.0, I have 5.2.9 Is there a way I can get the same results?
InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127
3
votes
1 answer

Sscanf and custom breaks

I have a string containg spaces and tags like: sp|P02671|FIBA_HUMAN Fibrinogen alpha chain OS=Homo sapiens GN=FGA PE=1 SV=2 I want to capture only the part after the description tag and before 'OS=' and was…
Bas Jansen
  • 3,273
  • 5
  • 30
  • 66
3
votes
4 answers

What does it mean in php to use strstr as a boolean check?

For example given code: if(strstr($key, ".")){ // do something } strstr returns a string, how can it be used as boolean? How does it turn true or false?
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
3
votes
3 answers

C-language strstr segmentation fault

i'm a beginner,tracks.c: #include #include char tracks[][5] = { "one", "two", "three", "four", "five", "six", }; void track_search(char search_for[]) { int i; puts(search_for); …
user1439114
  • 31
  • 1
  • 2
3
votes
4 answers

strstr vs regex in c

Let's say, for example, I have a list of user id's, access times, program names, and version numbers as a list of CSV strings, like this: 1,1342995305,Some Program,0.98 1,1342995315,Some Program,1.20 2,1342985305,Another…
cegfault
  • 6,442
  • 3
  • 27
  • 49
2
votes
1 answer

Function that finds a position of a substring s2 in s1

Here is the code: int position(char *s1, char *s2) { int i, j; for (i = 0; s1[i]; i++) { for (j = 0; s2[j] && s2[j] == s1[i + j]; j++); if (!s2[j]) return i; } return -1; } int main() { char word1[101],…
Sevo
  • 27
  • 2
2
votes
1 answer

How many this word in the array string

I want to count how many this word and operator in the string but I try to use strchr and it doesn't work. #include #include #include int main() { int x,count =0; char buff[100]="1+2.3(7^8)sin cos + cos…
2
votes
4 answers

My strstr function works, but a program designed to test it says it doesn't

for school, I have to recreate the strstr function. I did, and I tested it as much as I could, and everything seems to work perfectly. I am still looking into it but after several hours of troubleshooting, I don't get it. Can someone tell me what's…
Toyama70
  • 23
  • 3
2
votes
4 answers

strstr not returning desired result

Can you identify the error in this code, it's not being able to print the song even though I pass the valid parameters to find #include #include char tracks[][80] = { "I left my heart in Harvard Med School", "Newark,…
2
votes
3 answers

PHP: extract name from string

I have a path that looks like: /home/duke/aa/servers/**servername**/var/...morefiles... With php, I want to extract the "servername" from the path Unfortunately I'm not that well versed with php but I came up with something that used strstr() but I…
dukevin
  • 22,384
  • 36
  • 82
  • 111
2
votes
4 answers

strstr replace multiple variables in an array PHP

I'm working on a list of products that are written in multiple languages. I have an array for each product that displays it's languages like this: Array ( [0] => DA [1] => DE [2] => EN [3] => ES [4] => FI [5] => FR [6] => IT [7] => JA [8] => KO [9]…
dfcode3
  • 809
  • 1
  • 9
  • 15
2
votes
2 answers

Leetcode 28 - Implement strStr(): question

I am experiencing a bug in my submissions for Leetcode 28 that has thus far eluded me. My code works for most test cases but I am getting hung up on scenarios such as haystack = "mississippi", needle = "issip". I have tried debugging and found that…
artifc3
  • 77
  • 1
  • 1
  • 6
1 2
3
24 25