CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Find string in another string

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
overmindx



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

Find string in another string
PostPosted: Thu Oct 20, 2011 1:24 am     Reply with quote

Hi everybody,

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

View user's profile Send private message

PostPosted: Thu Oct 20, 2011 1:49 am     Reply with quote

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.

RF Developer
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group