|
-
May 11th, 1999, 09:30 AM
#1
Help on replacing part of a string
Path path(ToString(backUpPath));
VRIniInfo vrIniInfo = theApp.GetVRIniInfo();
CString lessonPath = vrIniInfo.GetLessonBasePath();
CString reponsePath = vrIniInfo.GetResponseBasePath();
CString destLesson = path.AppendToPath("Lavac\record.sav");
CString destResp = path.AppendToPath("Lavac\LECONS");
For example
lessonPath = C:\Lavac\LECONS
reponsePath = C:\Lavac\record.sav
destLesson = G:\temp\Lavac\LECONS
destResp = G:\temp\Lavac\record.sav
I need to be able to replace C:\ by G:\temp
Does anyone have a suggestion?
Thank You
-
May 11th, 1999, 10:40 AM
#2
Re: Help on replacing part of a string
Hows about this:
char path_buffer[_MAX_PATH];
//path_buffer contains the full pathname of your file
char new_path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( path_buffer, drive, dir, fname, ext );
_sprintf( new_path_buffer, "g:\\temp\\%s%s", fname, ext );
printf("New path is %s\n", new_path_buffer );
-
May 12th, 1999, 07:33 AM
#3
Re: Help on replacing part of a string
If you've got a recent version of MFC you can use CString::Replace():
CString oldPath = "C:\\path1\\path2";
oldPath.Replace("C:\\", "G:\\temp\\");
else if you can bear to link with Shlwapi.lib, you can use the shell utility path functions, especially PathSkipRoot():
#include "Shlwapi.h"
CString newRoot = "G:\\temp\\";
CString oldPath = "C:\\path1\\path2";
CString newPath = newRoot + PathSkipRoot(oldPath);
else it's just primitive CString stuff:
CString newRoot = "G:\\temp\\";
CString oldPath = "C:\\path1\\path2";
oldPath = newRoot + oldPath.Right(oldPath.GetLength() - 3);
[note: the '\\' is one character]
Dave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|