-
July 10th, 2013, 06:31 PM
#1
CString replace? index of?
Is there a function that can take out part of the string such as,
C:/Users
I want to take out Users.
I need the function to search for the first "/" and take out the last dir name
C:/windows would be c:
C:/users/bla would be c/users
Im programming in visual studio 6.0 MFC
-
July 10th, 2013, 08:11 PM
#2
Re: CString replace? index of?
Originally Posted by vaas
Is there a function that can take out part of the string such as,
C:/Users
I want to take out Users.
I need the function to search for the first "/" and take out the last dir name
C:/windows would be c:
C:/users/bla would be c/users
Im programming in visual studio 6.0 MFC
From the examples you posted, it looks more like you want to find the last /, in which case, ReverseFind and Left would give you what you need.
-
July 10th, 2013, 08:14 PM
#3
Re: CString replace? index of?
Originally Posted by vaas
Is there a function that can take out part of the string such as,
If you're working directly with path and file names, you should use what the CRT offers, and that is _splitpath.
http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
Regards,
Paul McKenzie
-
July 11th, 2013, 06:57 AM
#4
Re: CString replace? index of?
_splitpath doesn't split up subdirectories which the OP is asking about...
What you can do can be achieved by:
Use CString::ReverseFind() to find the last \ (you may or may not have to account for the fact the path may not have a \ or may be ending on a \)
Use CString::Mid() or CString::Right() or CString::Left() to extract the part you want
-
July 11th, 2013, 04:05 PM
#5
Re: CString replace? index of?
Building on what Paul said, since you are on Windows - I would use Shell Path Handling Functions.
Other than for exercise, it is a bad idea to work with the file names as strings.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
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
|