字符串查找函数
2014-08-05 12:24
218 查看
</pre><pre name="code" class="cpp">#include <iostream> // std::cout #include <string> // std::string int main () { std::string str ("There are two needles in this haystack with needles."); std::string str2 ("needle"); // different member versions of find in the same order as above: std::size_t found = str.find(str2); if (found!=std::string::npos) std::cout << "first 'needle' found at: " << found << '\n'; found=str.find("needles are small",found+1,6); if (found!=std::string::npos) std::cout << "second 'needle' found at: " << found << '\n'; found=str.find("haystack"); if (found!=std::string::npos) std::cout << "'haystack' also found at: " << found << '\n'; found=str.find('.'); if (found!=std::string::npos) std::cout << "Period found at: " << found << '\n'; // let's replace the first needle: str.replace(str.find(str2),str2.length(),"preposition"); //replace 用法 std::cout << str << '\n'; return 0; }
相关文章推荐
- PHP - Manual手册 - CLXI. String 字符串处理函数 - strpos查找一个字符串第一次出现的位置
- MemFindStrNoCase 字符串查找函数, 代码优化
- 设计一个程序,从键盘上输入若干字符串,利用算法库中的查找函数对给定的字符串进行查找,将查找后的结果输出
- 转贴 有关js 函数验证和字符串查找替换的方法
- C++字符串内部查找函数
- ColdFusion中常用几种字符串查找函数
- SQL - 查找 过程、函数、触发器 是否包含 某个指定 字符串
- 实现一个字符串查找子串的函数
- php strstr查找字符串中是否包含某些字符的查找函数
- 字符串内部查找函数
- Python函数——查找字符串第n次出现的位置
- sql查找某个字符串第N次出现的位置的函数(转帖)
- oracle中常用的字符串查找、替换以及截取函数的用法!
- PHP stristr() 函数(不区分大小写的字符串查找)
- 字符串内部查找函数
- 设置你想要的 分隔符号 比如,;/t 等,这个函数就可以在字符串里边查找分隔符号了
- Sqlite3 的扩展:实现 REGEXP函数和包含字符串查找的函数 CONTAIN
- 现成汉字字符串的模糊查找函数
- 自己实现的一个字符串分割截取函数,以及查找指定字符
- C语言字符串查找函数