How to Extract number after decimal in wchar*?

D.D.K-2637 966 Reputation points
2021-02-04T09:57:34.257+00:00

Hi,
I have some wchar* and I want to +1 the number after the sign. eg:
T1 -> T2 -> T3
T10 -> T11 -> T12
T1.1 -> T1.2 -> ... -> T1.9 -> T1.10 -> ..-> T1.100
maybe i need use regex pattern "\d+$" to separate the last number then +1
My problem is I'm not sure which syntax should use in C++
Please guide me!
Thanks you!

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,780 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118.4K Reputation points
    2021-02-04T10:33:12.963+00:00

    Check an approach:

    #include <string>
    #include <algorithm>
    #include <cwctype>
    
    . . .
    
    std::wstring text = L"T1.9";
    
    auto i = std::find_if_not( text.crbegin( ), text.crend( ), []( wchar_t c ) { return iswdigit( c ); } );
    
    std::wstring p( text.cbegin( ), i.base( ) );
    std::wstring n( i.base( ), text.cend( ) );
    
    std::wstring result = p + std::to_wstring( std::stoi( n ) + 1 );
    // Result: "T1.10"
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.