zoukankan      html  css  js  c++  java
  • string类型的查找

    sting s;

    记住典型的查找操作:

    s.find(args)                   

    s.find_fist_of(args)

    s.find_fist_not_of(args)

    还有3个逆序的查找操作,

    s.rfind(args)

    s.find_last_of(args)

    s.find_last_not_of(args)

    其中args可以为下面4个版本之一:

    c,pos

    s2,pos

    cp,pos

    cp,pos,n

    例子:

    /******************************************************************************
     * str.find(args)是完全匹配args中的字符串;
     * 注意:args是参数表(含要查找的字符或字符串参数),不是字符串!
     ********************************************************************************/
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    int main()
    {
    	string str = "helloWorLD";
    	string::size_type pos1 = str.find("Wor");
    	cout << pos1 << endl;
    
    	string::size_type pos2 = str.find("woa");
    	if (pos2 == string::npos) {
    		cout << "Do not find" << endl;
    	} else {
    		cout << pos2 << endl;;
    	}
    	return 0;
    }
    

    输出:

    5

    Do not find

    /******************************************************************************
     * str.find_first_of(args)只要在str中找到args中的字符串参数中的任意字符就返回;
     * 注意:args是参数表(含要查找的字符或字符串参数),不是字符串!
     ********************************************************************************/
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	string str = "he2l3l5oWo6rLD";
    	string::size_type pos = str.find_first_of("0123456789");
    	cout << pos << endl;
    	return 0;
    }
    

    输出:

    2

  • 相关阅读:
    Remote Procedure Call (RPC) Locator与X3
    Delphi的悬浮窗口
    改变CSS样式
    JavaScript 打印Web页面指定区域的信息
    判断页面元素存在与否
    如何处理HTML标签属性
    jQuery 获取和设置表单元素
    如何添加/移除CSS类
    处理网页内容
    正则表达式 收集
  • 原文地址:https://www.cnblogs.com/helloweworld/p/2824215.html
Copyright © 2011-2022 走看看