开发者

find last location in a string

i have a string

a = "hai my name is prasanth Madhavan"

and i would like to replace the space btw prasanth and Madhavan with a period.

whe开发者_StackOverflown i use a.find("prasanth") it gives the location of p i.e the begining of the search string. is ther a way to get the location of the ending of the string using find??


Add the length of the string you are looking for.


#include <string>

std::string str("hai my name is prasanth Madhavan");
std::string prasanth("prasanth");
std::size_t prasanth_pos = str.find(prasanth);
if (prasanth_pos != std::string::npos && prasanth_pos + prasanth.size() != str.size())
    str[prasanth_pos + prasanth.size()] = '.';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜