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
Re: CString replace? index of?
Quote:
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.
Re: CString replace? index of?
Quote:
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
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
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.