Is there a function to determine if a string is part of another string. I tried strcmp but it only determines if the string are exactly alike.
e.g.
Code:
str1 = "STRING ONE";
str2 = "STRING ONE";
So this will return zero to indicate that they are equal.
There is also strncmp which will only read a specified number of bytes.
e.g.
Code:
str1 = "STRING ONE";
str2 = "STRING";
So this will return zero to indicate the similarities of str1 and str2.
What I want is to determine if a string is part of string regardless its position to the other string
e.g.
Code:
str1 = "STRING NUMBER ONE";
str2 = "NUMBER";
This would still return an indication that str2 is part of str1.
Is there a way to do this? Thanks in advance.
RF_Developer
Joined: 07 Feb 2011 Posts: 839
Posted: Thu Oct 20, 2011 1:49 am
Take a look at strstr() it may help you.
This though is the sort of basic function thats often given as an exercise for the reader in typical C textbooks, so its very easy, and instructive, to roll your own.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum