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
0
votes
0 answers

How to count number of same elements from data using PHP

I'm trying to count frequency from input data. Here is e.g input including Y value / X value / User Key Y:5, X:3, User:A Y:12, x:1, User:B Y:66, X:2, User:A Y:180, X:3, User:C Y:328, X:4, User:D Y:549, X:3, User:D Y:765, X:2, User:A Most important…
Jason
  • 1
0
votes
3 answers

strstr doesn't work with the delimiter "\r\n\r\n"

i got the delimiter "\r\n\r\n" in the substring, and strstr is returning null Here is the code : #include #include #include int main(int ac, char **av) { char *ptr; ptr = strstr(av[1], "\r\n\r\n"); …
Zahreddine Laidi
  • 560
  • 1
  • 7
  • 20
0
votes
2 answers

C language and strings

#include #include int main() { char s3[12]="ABCDEISHERO"; char s4[5]="ABCDE"; char* p=strstr(s3,s4); printf("%s",p); return 0; } I wrote this code, but according to the functionality of strstr, we have…
Heatblast
  • 55
  • 6
0
votes
3 answers

PHP - strstr() doesn't work well with MySql

I have these tables in my DB: TABLE A: id | haystack ------------- 1 | 682,401 2 | 351 TABLE B: id | needle ------------- 1 | 352 2 | 682 3 | 978 All I want to do is to check if a haystack from table A contain any needle from table B. I did…
Cosmi
  • 67
  • 5
0
votes
0 answers

troubles finding a specific string in a structure

I'm trying to implement the following function but my code is not functional. Any ideas why? int *colecao_pesquisa_nome(colecao *c, const char *nomep, int *tam); Return an indices array referring to the position of all plants that present the…
House
  • 1
  • 1
0
votes
4 answers

Check if last character is "s" or "z"

is there a more gallant way to check if last character is "s" or "z" than: if (substr($var, -1, 1) == "s" OR substr($var, -1, 1) == "z") ... Something like if (substr($var, -1, 1) == "s" OR "z") ... would be nice, but is there something like…
Philip
  • 1,068
  • 3
  • 12
  • 21
0
votes
1 answer

c function definition calls for pointer but example does not use pointers

I relatively new to low level programming such as c. I am reviewing the strstr() function here. When reviewing the function definition char *strstr(const char *str1, const char *str2); I understand that function will return a pointer or a NULL…
S moran
  • 137
  • 4
0
votes
2 answers

Ignore comments from a line read with strstr in C

I have to write a code without third-party libraries that read from a file row by row and look for a switch or case operator. So far my code for that is this: while(fgets(st, 1001, f1)) { lineCnt++; if(strstr(st, "switch")) { …
acryxis
  • 3
  • 2
0
votes
2 answers

GetWindowText and substrings

I was having trouble getting a substring using strstr(a,b); To check if the "FiveM" name appears in the title bar of the window, because usually in this game the title bar also contains updates and so on so i was googling and i found the…
kraneqq
  • 19
  • 2
0
votes
1 answer

How to pass the tokens to strstr () for searching the similar strings?

I am trying to split the given string containing the spaces into multiple strings. Then I am trying to pass these strings/tokenz to the strstr() for searching the similar strings from the given file. The output should show the matched strings in the…
sanober
  • 21
  • 5
0
votes
1 answer

How to compare strings in C without hard coding the increments?

I have a buffer that holds a string from a CSV file that I opened and read. I split the string up by using strtok() and split on the " , ". So now my string looks like this: char buff[BUFFER_SIZE] = "1000" "CAP_SETPCAP" "CAP_NET_RAW" I want to…
ldd12345
  • 91
  • 5
0
votes
3 answers

STM32 - Strstr function does not work as I expected (UART)

I am trying to find specific string in another string which is received via UART. However, my function returns 0, although string is not inside uart received string. Here is my function: bool GetCommand(UART_HandleTypeDef *huart, char *command, char…
0
votes
1 answer

Using strstr with 2d array

I'm programming in C. I have loaded a 2d array with words. It is called dictionary[][]. I am trying to use strstr to find out how many of the words have a substring in them of "struct". Here is the code. In my function count_matches I try to…
CJF
  • 1
0
votes
2 answers

different results for php functions strpos and substr in localhost and server

suppose we have strings like "adjkadahsdjashd##kjhkhkjhkjhs" . and I want to cut them to for example adjkadahsdjashd and kjhkhkjhkjhs so I wrote this on my computer : "; echo…
Cyb3r
  • 187
  • 1
  • 1
  • 10
0
votes
3 answers

Find multiple characters in string AFTER substring

So I have this problem, where I have a string like this with points: "TaskA:55 TaskB:23....." etc. Is there a function with witch I can get the points from this? I'm familiar with strstr, but that returns me the pointer to the first letter of the…