Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:39:03+00:00 2026-06-04T04:39:03+00:00

Has anyone dealt with using std::string functions for MBCS? For example in C I

  • 0

Has anyone dealt with using std::string functions for MBCS? For example in C I could do this:

p = _mbsrchr(path, '\\');

but in C++ I’m doing this:

found = path.find_last_of('\\');

If the trail byte is a slash then would find_last_of stop at the trail byte? Also same question for std::wstring.

If I need to replace all of one character with another, say all forward slashes with backslashes what would be the right way to do that? Would I have to check each character for a lead surrogate byte and then skip the trail? Right now I’m doing this for each wchar:

if( *i == L'/' )
*i = L'\\';

Thanks

Edit: As David correctly points out there is more to deal with when working with multibyte codepages. Microsoft says use _mbclen for working with byte indices and MBCS. It does not appear I can use find_last_of reliably when working with the ANSI codepages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:39:04+00:00Added an answer on June 4, 2026 at 4:39 am

    You don’t need to do anything special about surrogate pairs. A single 16 bit character unit that is one half of a surrogate pair, cannot also be a non-surrogate character unit.

    So,

    if( *i == L'/' )
        *i = L'\\';
    

    is perfectly correct.

    Equally you can use find_last_of with wstring.

    It’s more complicated for multi-byte ANSI codepages. You do need to deal with lead and trail byte issues. My recommendation is to normalise to a more reasonable encoding if you really have to deal with multi-byte ANSI date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if this subversion bug has been dealt with? https://svn.apache.org/repos/asf/subversion/tags/1.6.9/www/faq.html#windows-access-denied I'm getting
has anyone else experienced this . I have SP1 but i have to kill
I'm doubting since this site is full of experts anyone has dealt with this,
Has anyone else had this issue and found a working solution? I've enabled the
Has anyone had this problem? I deleted a column in the table editor and
Has anyone else experienced this? I have uninstalled and reinstalled TortoiseSVN as well as
Has anyone seen this error before? An error occurred creating the configuration section handler
Ok, so this has been driving me mad for a while, but it occasionally
Has anyone created a custom Silverlight Splash screen to replace the blue balls circular
Has anyone compared the speed of performance between LINQ to SQL against the Entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.