For example : put from keyboard two strings, first amonijack, second codeamonijackcall.
How to check that in codeamonijackcall consists amonijack ?
7 replies to this topic
#1
Posted 11 January 2011 - 05:34 AM
|
|
|
#2
Posted 11 January 2011 - 05:40 AM
#3
Posted 11 January 2011 - 06:35 AM
Hello, you can download some regex library like this: Boost C++ Libraries. Learn something about it, its very useful.
Regards,
Infinity
Regards,
Infinity
#4
Posted 11 January 2011 - 06:53 AM
every one suggest that, for my problem some objectly advice ?
what to do when extract that ? :S
what to do when extract that ? :S
#6
Posted 11 January 2011 - 03:10 PM
i havent worked with class. I'am interested in simple way. Any code ? Any algorithm maybe ?
#7
Posted 11 January 2011 - 03:28 PM
You are learning c++ but you haven't learned "class"? You mean you are learning c.
One of the best quotes I've heard is: "the best programmers are lazy".
Meaning: why reinvent the wheel if you don't have to? you don't have to spend resources, time, and money trying to invent something that's already been done.
If you were assigned this as a problem for a class where you are supposed to design a function that does what you mentioned, then that's a different story, and please say so.
If you are just needing to parse a string and search for an occurrence of another string within it, then please consider using tools which have already been designed to suit that need such as the std::string class and the boost library like people have mentioned above.
One of the best quotes I've heard is: "the best programmers are lazy".
Meaning: why reinvent the wheel if you don't have to? you don't have to spend resources, time, and money trying to invent something that's already been done.
If you were assigned this as a problem for a class where you are supposed to design a function that does what you mentioned, then that's a different story, and please say so.
If you are just needing to parse a string and search for an occurrence of another string within it, then please consider using tools which have already been designed to suit that need such as the std::string class and the boost library like people have mentioned above.
#8
Posted 11 January 2011 - 06:59 PM
Amonijack said:
i havent worked with class. I'am interested in simple way. Any code ? Any algorithm maybe ?
Did you even look at the link I posted? I suppose not, so here is the code I wrote...
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
if (argc > 2)
{
char* Phrase = argv[1];
char* SearchString = argv[2];
int found = 0;
// loop through the phrase
for (int i = 0; i < strlen(Phrase); i++)
{
// did we find a char that is the beginning of our substring?
if (Phrase[i] == SearchString[0])
{
// lest see if all of the characters match our substring.
for (int k = 0; k < strlen(SearchString); k++)
{
// loop through the phrase by our substring length.
if (Phrase[i+k] == SearchString[k])
{
found++;
if (found == strlen(SearchString))
cout << "\"" << argv[2] << "\" is a substring of \"" << argv[1] << "\"" << endl;
}
}
}
}
if (found != strlen(SearchString))
cout << "\"" << argv[2] << "\"is not a substring of \"" << argv[1] << "\"" << endl;
}
else
cout << "The correct usage is: \"phrase\" \"substring\"";
return 0;
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









