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. I need your help on this guys...

I need your help on this guys...

Scheduled Pinned Locked Moved C / C++ / MFC
questionjavascripthelptutorial
2 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.
  • B Offline
    B Offline
    blink4me
    wrote on last edited by
    #1

    Hi, I actually have 3 ?s: 1- How can I convert a CString to a c-char (char[25]) and vice-versa. 2- How can I convert a CString to a int, fl int or other number holder. 3- How can I extract a certain portion of a CString, like the first 2 chars for example. // JS Paquet cout << "Thank you all" << endl;

    D 1 Reply Last reply
    0
    • B blink4me

      Hi, I actually have 3 ?s: 1- How can I convert a CString to a c-char (char[25]) and vice-versa. 2- How can I convert a CString to a int, fl int or other number holder. 3- How can I extract a certain portion of a CString, like the first 2 chars for example. // JS Paquet cout << "Thank you all" << endl;

      D Offline
      D Offline
      Derek Waters
      wrote on last edited by
      #2
      1. If you don't need to modify the char array, you can simply cast a CString to an LPCTSTR (long? pointer const TCHAR string):

      LPCTSTR apszBuffer = (LPCTSTR)m_MyCstring;

      If you need to modify the buffer, you need to use GetBuffer and ReleaseBuffer:

      LPTSTR apszMyBuffer = m_MyCString.GetBuffer(m_MyCString.GetLength());
      // Do something with apszMyBuffer, changing its length to 25
      m_MyCString.ReleaseBuffer(25);

      1. Use atoi, atof (or _ttoi for wide-char compatibility):

      int viValue = atoi("25478");
      float vfValue = atof("123.456");

      1. Use CString::Mid():

      CString vstrBit = m_MyCString.Mid(0, 2); // First two chars
      CString vstrAnother = m_MyCString.Mid(5, 4); // Chars 5-8

      Hope this helps. ------------------------ Derek Waters derek@lj-oz.com

      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