In article <_Z**************@fe03.lga>,
"Jim Langston" <ta*******@rocketmail.com> wrote:
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net... In article <11*********************@g47g2000cwa.googlegroups. com>,
"noopathan" <ms*****@gmail.com> wrote:
I have two strings as below
string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";
I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";
Early code help is greatly appreciated.
regards
Jango
assert( A.rfind('.') != string::npos );
string C = A.substr( A.rfind('.') + 1 );
Don't use assert for something like this you want to put into production.
Once you turn off debug mode asserts disappear. So it would totally ignore
that. I would rather do:
std::string C;
if ( A.rfind('.') != string::npos )
C = A.substr( A.rfind('.') + 1 );
That'll work in production or debug. Yes, it assigns a null string and
doesn't bring up an error box, but you can MessageBox if you want manually.
It all depends on what you want to accomplish. Your solution is good if
the program should expect to occasionally get a string without a '.' in
it (for example if the user is entering the string.)
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.