• 【C++】string通过key获取值


    string StringTest::core_get_param_by_key(string data, string key)
    {
    int pos = 0;
    int count = 0;
    string str_sub = "";
    string str_result = "";
    string str_split = """;

    // format: "key":"value","key2"...

    // 方式1

    key = key + "":"";
    printf("***********key=%s ", key.c_str());
    pos = data.find(key);
    if (pos == string::npos) {
    return str_result;
    }
    str_sub = data.substr(pos + key.length(), data.length());
    printf("***********str_sub=%s ", str_sub.c_str());
    pos = str_sub.find(str_split);
    str_result = str_sub.substr(0, pos);
    printf("***********pos=%d, str_result=%s ", pos, str_result.c_str());
    #if 0

    //方式2
    pos = data.find(key);
    if (pos == string::npos) {
    return str_result;
    }
    str_sub = data.substr(pos + key., data.length());
    int size = str_sub.size();
    pos = str_sub.find(str_split);
    while (pos != string::npos) {
    str_result = str_sub.substr(0, pos);
    str_sub = str_sub.substr(pos + 1, size);
    pos = str_sub.find(str_split);
    size = str_sub.length();
    count++;
    if (count >= 3) {
    break;
    }
    }
    #endif
    return str_result;
    }

  • 相关阅读:
    IDEA快捷方式
    JVM调优总结
    log4g详细配置
    大前端完整学习路线(详解)
    Tomcat工作原理
    Oracle
    Servlet知识
    lmap
    常见博客API
    PL/SQL入门理解(一)
  • 原文地址:https://www.cnblogs.com/zwh0214/p/15466350.html
Copyright © 2020-2023  润新知