Find escaped characters in a string line

自闭症网瘾萝莉.ら 提交于 2019-12-12 23:34:22

问题


Using the std library, and the function find, how can I know if there are any escaped characters in the given string ?

For instance :

string line = "bla bla bla \n blabla";
bool hasEscapedSequence = (line.find("\n",0) < line.size());

This obviously won't work since the \n in the find will be escaped. If I try (line.find("\\n",0) < line.size());, it doesn't seem to change anything

How should I do ?


回答1:


line.find("\n",0)

Will return the position of the cursor where it will find the substring. If the substring is not found it will return string::npos. And so it should not be compared with the size.

bool hasEscapedSequence = (line.find("\n") != string::npos);


来源:https://stackoverflow.com/questions/28028231/find-escaped-characters-in-a-string-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!