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++ 标记字符串

      C++ Tokenize String(C++ 标记字符串)
      <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++ 标记字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)
                <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>

                    <tbody id='u6WG0'></tbody>

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

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