Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 10-Jul-13 13:28pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Jul-13 19:16pm    
And what prevented you from just reading the documentation? Why do you think CodeProject should act as a plain reference?
—SA

1 solution

All you need is this:
http://www.cplusplus.com/reference/string/string/find/[^],
http://www.cplusplus.com/reference/string/string/erase/[^].

If you are using "regular" null-terminated strings instead, you have two options: 1) stop using then and switch to std::string; 2) initialize some instances of std::string, perform required operations and get back to null-terminated when you need them.

If you use MFC, you can alternatively use MFC CString. Please see: http://msdn.microsoft.com/en-us/library/ms174288%28v=vs.110%29.aspx[^].

Be sure you consult proper documentation before asking questions. This is the reference you need the most: Microsoft Q209354 :-).
(No offense, please; this is what you really want :-).)

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900