Find last index of a character in a string | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Anant Patni.

Please Like, Comment and Share the Video among your friends.

Install our Android App:

If you wish, translate into local language and help us reach millions of other geeks:

Follow us on Facebook:

And Twitter:

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

Are you the owner of geeks for geeks website

Jjfjfjfjnns
Автор

You should at least provide C/STL solutions for problems such as this. It's useful on the one hand to know how to solve the problem in the abstract, but it is typically not a good idea to roll your own solutions in code when standard library functions have been provided to perform the same task (because: 1) code correctness; 2) code bloat). In real world software we are encouraged to always use standard template library methods and algorithm functions for C++ code - as this example is - and standard C library functions where possible for C code.

E.g.:

const char* p;
int index = (int)(((p = std::strrchr(str.c_str, x)) != nullptr) ? (std::ptrdiff_t)(p - str.c_str) : (std::ptrdiff_t)-1);

or:

int index = (int)str.rfind(x);

xf