Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. string manipulation question

string manipulation question

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nm_114
    wrote on last edited by
    #1

    when is it ok to do pch++ and when should you use CharNext/_tcsinc? I'm guessing pch++ is fine for ansi char* and unicode TCHAR* for english, so do you use CharNext/_tcsinc for programs that will have text in a non-english encoding, a non-western european encoding? - thanks

    J 1 Reply Last reply
    0
    • N nm_114

      when is it ok to do pch++ and when should you use CharNext/_tcsinc? I'm guessing pch++ is fine for ansi char* and unicode TCHAR* for english, so do you use CharNext/_tcsinc for programs that will have text in a non-english encoding, a non-western european encoding? - thanks

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      pch++ can be used for WCHAR* or, if you know the string is using a code page in which there are no multi-byte chars (e.g., English, Spanish, French), for char* too. CharNext or _tcsinc are used when you want to write code that can be used, whithout changes, either for SBCS, MBCS, or Unicode builds. For example, the following code:

      _TCHAR buffer[] = _T("This is a test");
      int nLen = 0;
      for (const _TCHAR* pch = buffer; *pch; pch = _tcsinc(pch))
      {
        nLen++;
      }

      gets expanded as follows:

      // SBCS (when neither _MBCS nor _UNICODE are defined)
      char buffer[] = "This is a test";
      int nLen = 0;
      for (const char* pch = buffer; *pch; pch = _strinc(pch))
      {
        nLen++;
      }

      // UNICODE (when _UNICODE is defined)
      wchar_t buffer[] = L"This is a test";
      int nLen = 0;
      for (const wchar_t* pch = buffer; *pch; pch = _wcsinc(pch))
      {
        nLen++;
      }

      // MBCS (when _MBCS is defined)
      char buffer[] = "This is a test";
      int nLen = 0;
      for (const char* pch = buffer; *pch; pch = _mbsinc(pch))
      {
        nLen++;
      }

      See also: A Sample Generic-Text Program[^] -- jlr http://jlamas.blogspot.com/[^]

      N 1 Reply Last reply
      0
      • J Jose Lamas Rios

        pch++ can be used for WCHAR* or, if you know the string is using a code page in which there are no multi-byte chars (e.g., English, Spanish, French), for char* too. CharNext or _tcsinc are used when you want to write code that can be used, whithout changes, either for SBCS, MBCS, or Unicode builds. For example, the following code:

        _TCHAR buffer[] = _T("This is a test");
        int nLen = 0;
        for (const _TCHAR* pch = buffer; *pch; pch = _tcsinc(pch))
        {
          nLen++;
        }

        gets expanded as follows:

        // SBCS (when neither _MBCS nor _UNICODE are defined)
        char buffer[] = "This is a test";
        int nLen = 0;
        for (const char* pch = buffer; *pch; pch = _strinc(pch))
        {
          nLen++;
        }

        // UNICODE (when _UNICODE is defined)
        wchar_t buffer[] = L"This is a test";
        int nLen = 0;
        for (const wchar_t* pch = buffer; *pch; pch = _wcsinc(pch))
        {
          nLen++;
        }

        // MBCS (when _MBCS is defined)
        char buffer[] = "This is a test";
        int nLen = 0;
        for (const char* pch = buffer; *pch; pch = _mbsinc(pch))
        {
          nLen++;
        }

        See also: A Sample Generic-Text Program[^] -- jlr http://jlamas.blogspot.com/[^]

        N Offline
        N Offline
        nm_114
        wrote on last edited by
        #3

        thanks for the reply. just wondering, do you know of any reference that tells which code pages are multi-byte, which are single-byte? - thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups