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. Mobile Development
  3. Mobile
  4. how to go from CString to char []

how to go from CString to char []

Scheduled Pinned Locked Moved Mobile
tutorial
4 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.
  • R Offline
    R Offline
    rodneyk1
    wrote on last edited by
    #1

    can anyone tell me how to convert or mask a CString to a char [] i.e. (char new[]). In need to do this for my combo box. Thanks guys, Rod

    D 1 Reply Last reply
    0
    • R rodneyk1

      can anyone tell me how to convert or mask a CString to a char [] i.e. (char new[]). In need to do this for my combo box. Thanks guys, Rod

      D Offline
      D Offline
      Daniel Strigl
      wrote on last edited by
      #2

      Take a look at Strings on Pocket PC, Unicode and ANSI.

      char* GetAnsiString(const CString &s, UINT nCodePage)
      {
      int nSize = s.GetLength();
      char *pAnsiString = new char[nSize+1];

      WideCharToMultiByte(nCodePage, 0, s, nSize+1, pAnsiString, nSize+1, NULL, NULL);
      return pAnsiString;
      }

      CString strUnicode = _T("Some test string");
      char *pAnsiString = GetAnsiString(strUnicode, CP_ACP);

      Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)

      R 1 Reply Last reply
      0
      • D Daniel Strigl

        Take a look at Strings on Pocket PC, Unicode and ANSI.

        char* GetAnsiString(const CString &s, UINT nCodePage)
        {
        int nSize = s.GetLength();
        char *pAnsiString = new char[nSize+1];

        WideCharToMultiByte(nCodePage, 0, s, nSize+1, pAnsiString, nSize+1, NULL, NULL);
        return pAnsiString;
        }

        CString strUnicode = _T("Some test string");
        char *pAnsiString = GetAnsiString(strUnicode, CP_ACP);

        Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)

        R Offline
        R Offline
        rodneyk1
        wrote on last edited by
        #3

        Thanks Daniel , Worked great, do you know how to convert ctime to cstring? I am trying to get data from a datepicker and it gives me a CDateTimeCtrl.I think I have converted to a CTime but How do I convert that to a cString to write it to a file. Here is what I have for code. CString szChoice; CTime date; m_date.GetTime(date); szChoice = date.Format(L"%x"); fileRead(L"Date: " + szChoice+ " \r" ) Thanks, Rod

        D 1 Reply Last reply
        0
        • R rodneyk1

          Thanks Daniel , Worked great, do you know how to convert ctime to cstring? I am trying to get data from a datepicker and it gives me a CDateTimeCtrl.I think I have converted to a CTime but How do I convert that to a cString to write it to a file. Here is what I have for code. CString szChoice; CTime date; m_date.GetTime(date); szChoice = date.Format(L"%x"); fileRead(L"Date: " + szChoice+ " \r" ) Thanks, Rod

          D Offline
          D Offline
          Daniel Strigl
          wrote on last edited by
          #4

          CTime to CString:

          CString szChoice;
          CTime date;
          m_date.GetTime(date);
          //szChoice = date.Format(L"%x");
          szChoice.Format(L"%02d.%02d.%02d", date.GetDay(), date.GetMonth(), dat.GetYear());
          fileRead(L"Date: " + szChoice+ L"\r");

          and of course: A Date and Time formatter Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)

          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