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. About CString : Plz Send Urgently

About CString : Plz Send Urgently

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialannouncement
8 Posts 7 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.
  • P Offline
    P Offline
    parims
    wrote on last edited by
    #1

    How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

    K P K V Y 5 Replies Last reply
    0
    • P parims

      How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

      K Offline
      K Offline
      karmendra_js
      wrote on last edited by
      #2

      hey buddy use CStringT::Tokenize (as far as i think CString and CStringT functions same). following is an exmple i found for you form msdn go through it. Example: The following example demonstrates the use of CStringT::Tokenize. //typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString; CAtlString str( "%First Second#Third" ); CAtlString resToken; int curPos= 0; resToken= str.Tokenize("% #",curPos); while (resToken != "") { printf("Resulting token: %s\n", resToken); resToken= str.Tokenize("% #",curPos); }; Output: Resulting Token: First Resulting Token: Second Resulting Token: Third

      1 Reply Last reply
      0
      • P parims

        How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        CString str="C:\MyDocuments\myDialog\release\myapp.exe"
        int indx=str.ReverseFind('\\');
        if (indx!=-1)
        CString fileName=str.Right(indx);

        1 Reply Last reply
        0
        • P parims

          How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          Why don't you check out the Class Members in CString? Well, here goes: Solution 1, CString: CString cs = "C:\\MyDocuments\\myDialog\\release\\myapp.exe"; CString pureFileName; int lastSlashOffset = cs.ReverseFind((TCHAR) '\\'); if(lastSlashOffset >= 0 && cs.GetLength > (lastSlashOffset + 1)) { pureFileName = cs.Mid(pureFileName + 1); } // pureFileName contains the file name. Solution 2 (good old splitpath): #include #include void main( void ) { char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; strcpy(path_buffer, "C:\\MyDocuments\\myDialog\\release\\myapp.exe"); _splitpath( path_buffer, drive, dir, fname, ext ); printf( "Path extracted with _splitpath:\n" ); printf( " Drive: %s\n", drive ); printf( " Dir: %s\n", dir ); printf( " Filename: %s\n", fname ); printf( " Ext: %s\n", ext ); } Output Path extracted with _splitpath: Drive: c: Dir: \MyDocuments\myDialog\release\ Filename: myapp Ext: .exe

          1 Reply Last reply
          0
          • P parims

            How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

            V Offline
            V Offline
            vikas amin
            wrote on last edited by
            #5

            This is the code that i have Tested with VC.6 it is actually the correction of the answer posted to the quetion . If ur using CString so its VC++ and for VC++ this format is preferable.:-O CString str1="C:\\MyDocuments\\myDialog\\release\\myapp.exe"; int indx=str1.ReverseFind('\\'); indx++; if (indx!=-1) CString fileName=str1.Mid(indx); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

            P 1 Reply Last reply
            0
            • V vikas amin

              This is the code that i have Tested with VC.6 it is actually the correction of the answer posted to the quetion . If ur using CString so its VC++ and for VC++ this format is preferable.:-O CString str1="C:\\MyDocuments\\myDialog\\release\\myapp.exe"; int indx=str1.ReverseFind('\\'); indx++; if (indx!=-1) CString fileName=str1.Mid(indx); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              OOps ! I forgot to increment. thanks Vikas.

              1 Reply Last reply
              0
              • P parims

                How to split the string based on new line character. I have a string i.e., C:\MyDocuments\myDialog\release\myapp.exe I want to retrive exe name . (ie., myapp.exe) How it is possible. I want to retrive right last exe name for all paths. Give a flexible code. Praveen Chowdam Kumar

                Y Offline
                Y Offline
                YoSilver
                wrote on last edited by
                #7

                #include "shlwapi.h"
                // add shlwapi.lib to the linker in project options

                // source path name
                CString strPathName = _T("C:\\MyDocuments\\myDialog\\release\\myapp.exe");

                // call the shlwapi.dll function
                LPTSTR pszFileName = PathFindFileName(strPathName); // auto cast
                CString strFileName = pszFileName;

                Never forget to search MSDN. That's all, folks! ;P One always gets the deserved.

                T 1 Reply Last reply
                0
                • Y YoSilver

                  #include "shlwapi.h"
                  // add shlwapi.lib to the linker in project options

                  // source path name
                  CString strPathName = _T("C:\\MyDocuments\\myDialog\\release\\myapp.exe");

                  // call the shlwapi.dll function
                  LPTSTR pszFileName = PathFindFileName(strPathName); // auto cast
                  CString strFileName = pszFileName;

                  Never forget to search MSDN. That's all, folks! ;P One always gets the deserved.

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  YoSilver wrote: PathFindFileName(strPathName); Similarly you can use _tSplitPath() api also

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV

                  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