1. <tfoot id='05a33'></tfoot>

      <small id='05a33'></small><noframes id='05a33'>

    1. <legend id='05a33'><style id='05a33'><dir id='05a33'><q id='05a33'></q></dir></style></legend>
        <bdo id='05a33'></bdo><ul id='05a33'></ul>
    2. <i id='05a33'><tr id='05a33'><dt id='05a33'><q id='05a33'><span id='05a33'><b id='05a33'><form id='05a33'><ins id='05a33'></ins><ul id='05a33'></ul><sub id='05a33'></sub></form><legend id='05a33'></legend><bdo id='05a33'><pre id='05a33'><center id='05a33'></center></pre></bdo></b><th id='05a33'></th></span></q></dt></tr></i><div id='05a33'><tfoot id='05a33'></tfoot><dl id='05a33'><fieldset id='05a33'></fieldset></dl></div>

      C++ 标记字符串

      时间:2023-08-26
      <i id='hvJfN'><tr id='hvJfN'><dt id='hvJfN'><q id='hvJfN'><span id='hvJfN'><b id='hvJfN'><form id='hvJfN'><ins id='hvJfN'></ins><ul id='hvJfN'></ul><sub id='hvJfN'></sub></form><legend id='hvJfN'></legend><bdo id='hvJfN'><pre id='hvJfN'><center id='hvJfN'></center></pre></bdo></b><th id='hvJfN'></th></span></q></dt></tr></i><div id='hvJfN'><tfoot id='hvJfN'></tfoot><dl id='hvJfN'><fieldset id='hvJfN'></fieldset></dl></div>
        <tbody id='hvJfN'></tbody>
      <tfoot id='hvJfN'></tfoot>

      <small id='hvJfN'></small><noframes id='hvJfN'>

      <legend id='hvJfN'><style id='hvJfN'><dir id='hvJfN'><q id='hvJfN'></q></dir></style></legend>
      • <bdo id='hvJfN'></bdo><ul id='hvJfN'></ul>

                本文介绍了C++ 标记字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在寻找一种简单的方法来标记字符串输入,而无需使用非默认库,例如 Boost 等.

                I'm looking for a simple way to tokenize string input without using non default libraries such as Boost, etc.

                例如,如果用户输入四十_五,我想使用_作为分隔符来分隔四十和五.

                For example, if the user enters forty_five, I would like to seperate forty and five using the _ as the delimiter.

                推荐答案

                将字符串转换为标记向量(线程安全):

                To convert a string to a vector of tokens (thread safe):

                std::vector<std::string> inline StringSplit(const std::string &source, const char *delimiter = " ", bool keepEmpty = false)
                {
                    std::vector<std::string> results;
                
                    size_t prev = 0;
                    size_t next = 0;
                
                    while ((next = source.find_first_of(delimiter, prev)) != std::string::npos)
                    {
                        if (keepEmpty || (next - prev != 0))
                        {
                            results.push_back(source.substr(prev, next - prev));
                        }
                        prev = next + 1;
                    }
                
                    if (prev < source.size())
                    {
                        results.push_back(source.substr(prev));
                    }
                
                    return results;
                }
                

                这篇关于C++ 标记字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 C++ 中是否有内置的拆分字符串的方法? 下一篇:从 C/C++ 中的 TCP 套接字读取的正确方法是什么?

                相关文章

                <legend id='u6WG0'><style id='u6WG0'><dir id='u6WG0'><q id='u6WG0'></q></dir></style></legend>
                <i id='u6WG0'><tr id='u6WG0'><dt id='u6WG0'><q id='u6WG0'><span id='u6WG0'><b id='u6WG0'><form id='u6WG0'><ins id='u6WG0'></ins><ul id='u6WG0'></ul><sub id='u6WG0'></sub></form><legend id='u6WG0'></legend><bdo id='u6WG0'><pre id='u6WG0'><center id='u6WG0'></center></pre></bdo></b><th id='u6WG0'></th></span></q></dt></tr></i><div id='u6WG0'><tfoot id='u6WG0'></tfoot><dl id='u6WG0'><fieldset id='u6WG0'></fieldset></dl></div>

                  1. <small id='u6WG0'></small><noframes id='u6WG0'>

                      <bdo id='u6WG0'></bdo><ul id='u6WG0'></ul>
                    <tfoot id='u6WG0'></tfoot>