Good C++ string manipulation library

后端 未结 7 864
梦谈多话
梦谈多话 2021-01-30 01:05

I\'m sorry for flaming std::string and std::wstring. They are quite limited and far from being thread safe. Performance wise, they are not that good too. I miss simple features

相关标签:
7条回答
  • 2021-01-30 01:28

    The C++ String Algorithms Library from Boost has pretty much all of the features you need.

    0 讨论(0)
  • 2021-01-30 01:30

    For conversion, you can always break down and use the C library cstdlib.

    #include <cstlib>
    #include <iostream>
    
    int main()
    {
       std::string num;
    
       std::cin >> num;
    
       someFunc(atoi(num));
       someOtherFunc(atof(num));
       return 0;
    }
    

    atoi = ascii to integer atof = ascii to float

    As for find, use the STL function "find" defined under header algorithm, or find_first_of (or similar). I also believe you can initialize a vector of char's with an std::string, but that is conjecture.

    0 讨论(0)
  • 2021-01-30 01:32

    Bstring - Although I never tried it myself, the feature set and speed presented at their site. Under your choice of GPL or BSD license is also a good degree of freedom.

    Also, the name suggests it's better so how can they lie? :)

    0 讨论(0)
  • 2021-01-30 01:35

    The C++ String Toolkit (StrTk) Library is a free library that consists of robust, optimized and portable generic string processing algorithms and procedures for the C++ language. The library is designed to be easy to use and integrate within existing code.

    The library has the following capabilities:

    • Generic string tokenizer and token iterators
    • Split routines
    • User specified delimiter and splitter policies (simple and regex based etc.)
    • Conversions between data and hex and base-64
    • In-place removal and replace routines
    • Wild-card matching and globing
    • Fast 2D token grid processing
    • Extensible string processing templates

    and plenty more...

    Compatible C++ Compilers:

    • GCC 4.0+
    • Intel C++ Compiler 9.0+
    • Microsoft Visual C++ 8.0+
    • Comeau C/C++ 4.1+

    Source:

    • Download: http://www.partow.net/programming/strtk/index.html
    • SVN: http://code.google.com/p/strtk/
    0 讨论(0)
  • 2021-01-30 01:35

    I found wxString convenient to use and it has many features. Although it is part of a bigger library (wxWidgets) and maybe just too big when you just want to use strings. It also works without GUI components when you just use wxBase which contains the wxString and a 'few' other components.

    EDIT: here is a link to the documentation. It accepts the standard functions of std::string and also a few others. I always find the BeforeFirst() and AfterFirst() very convenient when I have to parse some text. And it is really well documented.

    0 讨论(0)
  • 2021-01-30 01:38

    I'm not sure I agree. Strings really shouldn't be thread-safe due to the overhead, except for reference-counting, if applicable. Most of the other functionality you want would turn strings into a garbage barge. Likewise, removing dependencies would remove their ability to work well with streams.

    The one thing I'd suggest is that we could benefit from an immutable string class, particularly one that has no memory ownership or termination. I've written those before and they can be very helpful.

    0 讨论(0)
提交回复
热议问题