About CString : Plz Send Urgently
-
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
-
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
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
-
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
CString str="C:\MyDocuments\myDialog\release\myapp.exe"
int indx=str.ReverseFind('\\');
if (indx!=-1)
CString fileName=str.Right(indx); -
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
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
-
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
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 -
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.comOOps ! I forgot to increment. thanks Vikas.
-
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
#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.
-
#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.
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