Replace UNICODE chars to non-UNICODE in std::string

Flaviu_ 991 Reputation points
2022-07-06T09:08:02.067+00:00

I have the following std::string:

Mureș  

How can I replace the last UNICODE char to non-UNICODE ?

I have tried:

s = std::regex_replace(s, std::regex("ș"), "a");  

but I got:

Unhandled exception at 0x75ECC3A2 in MyApp.exe: Microsoft C++ exception: std::regex_error at memory location 0x004FF450.  

Beside of that, I have a warning:

warning C4566: character represented by universal-character-name '\u255A' cannot be represented in the current code page (1252)  
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,742 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Flaviu_ 991 Reputation points
    2022-07-06T14:57:10.38+00:00

    It's ok now, I used:

    size_t pos;
    while ((pos = temp.find(L"ș")) != std::string::npos)
    {
    temp.replace(pos, 2, L"s");
    }

    I try to see if this could be accomplished with std::replace.

    0 comments No comments

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.