Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

analysing strings

Posted on 2002-07-23
7
Medium Priority
?
186 Views
Last Modified: 2010-04-01
I have a string[240] and I want to search this string for several different words.  The words could be in any part of the string.
is there a function that will search the string for the specified word or do i need to create one?
0
Comment
Question by:Karls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:Serega
ID: 7171225
strstr can help you, I think...

strstr - Find a substring

char *strstr( const char *string, const char *strCharSet );

returns a pointer to the first occurrence of strCharSet in string, or NULL if strCharSet does not appear in string.
0
 
LVL 84

Expert Comment

by:ozo
ID: 7171228
#include <string.h>
char *strstr (const char *s1, const char *s2);
0
 
LVL 1

Expert Comment

by:himmya
ID: 7171657
hi,

 u can use find member from basic strings....

  string str("ur string over here");

  if(str.find("ur world")>=0)
       found the word in string

u can use the no of find just go through the documentation of find() overloaded versions...

i think this will help u ......

rgds,
himmya.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:Sabnis
ID: 7171714
if you want the C-Style search then use the function above to locate the strings....within a for loop....or use a C++ style STL string class and use its member function find...again within a for loop
0
 
LVL 30

Expert Comment

by:Axter
ID: 7172748
Hi (himmya ), welcome to EE.

All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.

An answer should not be posted as an answer, if other experts have previously posted possible answers as comments, and/or have already made contributions to the question.

There are many experts who never post answers as answer.  Instead, they post their answers as comments.

If you read the following link, you'll see why this is the preferred method for many of our valued experts, including myself.

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hi (Karls):
Feel free to click the [Reject Answer] button near (Answer-poster's) response, even if it seems like a good answer.
Doing so will increase your chance of obtaining additional input from other experts.  Later, you can click the [Select Comment as Answer] button on any response.
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 7172768
The following is example code using STL method

#include <string>
#include <iostream>


int main()
{
     std::string Source = "This is a test to see if this works";

     for(size_t i = Source.find("is");
               i != std::string::npos;
               i = Source.find("is", i+1))
     {
          std::cout << "Found key word at position " << i << std::endl;
     }
     
    return 1;
}

You should compare the return of string::find with std::string::npos in order to determind if the string was found.
A value of std::string::npos, means the string was not found.

To futher iterate through the string, pass a second argument to the string::find function, which tells the function the starting point for the new search.
0
 

Author Comment

by:Karls
ID: 7176225
Thats what I was looking for.
You don't actually need to do it in a for loop though.  will do the entire line.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question