zoukankan      html  css  js  c++  java
  • c++字符串操作

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        string nam("http://1212121");
        if (nam.compare(0, 4, "http") == 0)
        {
            cout<<"equal"<<endl;
        }
        cout<<nam.substr(0,4)<<endl;
        string num("0123456789");
        string n("1a3");
        if (num.find(n[0]) != string::npos) {
            cout<<"container"<<endl;
        }
        if (num.find(n[1]) == string::npos) {
            cout<<" no container"<<endl;
        }
        cout<<num.find(n[1])<<endl;
    
        string ip("http://128.0.0.1/alibab.com");
        if (ip.find("127.0.0.1") == string::npos){
            cout<<" no ip container"<<endl;
        }
        return 0;
    }

    output:

    equal
    http
    container
    no container
    18446744073709551615
    no ip container

    欢迎评论交流
  • 相关阅读:
    优秀数
    加法检测器
    数字转换
    选课
    二叉苹果树
    分离与合体
    括号配对
    凸多边形的划分
    能量项链
    石子合并
  • 原文地址:https://www.cnblogs.com/linengier/p/8932166.html
Copyright © 2011-2022 走看看