Click here to Skip to main content
12,253,633 members (52,082 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hello guys

I want to cut out a part of a path but don't know how.
To get the path, I use this code:
String path = System.IO.Path.GetDirectoryName(fullyQualifiedName);
(path = "Y:\\Test\\Project\\bin\\Debug")

Now I need the first part without "\\bin\\Debug".
How can I cut this part out of the current path?


I'm thankful for all answers.

Greetings
Epanjohura
Posted 19-Jul-13 3:17am
Edited 21-Jul-13 20:35pm
v2
Comments
   
Why "MFC"? What prevents you from just reading the documentation?
—SA
ThePhantomUpvoter 19-Jul-13 9:22am
   
Pick a programming language first. The answers you get are probably going to be vastly different. But for either one you chose, using a combination of SubString and IndexOf will probably do the trick.
Sergey Alexandrovich Kryukov 19-Jul-13 11:25am
   
It's C#, "MFC" could be a slip of a hand. :-)
—SA
ridoy 19-Jul-13 11:10am
   
do you want it in C# or C++?
epanjohura 22-Jul-13 2:35am
   
c#, my fault.. but thanks for every help, I solved the problem
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You don't mention whether you want it in C++ or C#. But your coding pattern seems me it is in C#. Another question,is your above path static?
If so then you can do it within only 3 lines.
String path= @"Y:\\Test\\Project\\bin\\Debug";
String[] extract = Regex.Split(path,"bin");  //split it in bin
String main = extract[0].TrimEnd('\\'); //extract[0] is Y:\\Test\\Project\\ ,so exclude \\ here
Console.WriteLine("Main Path: "+main);//get main path
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Your tags are a bit puzzling since you tagged C# and MFC, which don't play well together. The answers you have so far are related to C#. If you are using MFC, that means C++, and you can use _splitpath()/_wsplitpath()[^] and then either std::string[^] or CString[^] to extract or replace parts of the path.

CString works with ANSI or Unicode, std::string is ANSI only. Both have their own vocal self righteous religious lobbies.
  Permalink  
Comments
Sergey Alexandrovich Kryukov 19-Jul-13 11:24am
   
It's a good point, even though the question is apparently on .NET, 5ed.
(Ha, someone decided to down-vote both answers. Funny :-)
—SA
Maciej Los 19-Jul-13 14:35pm
   
Good point!
+5!
epanjohura 22-Jul-13 2:36am
   
thank you so much for your help
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You cannot modify any string; strings are immutable, so all string methods changing the string actually create a new string object. You can use this one: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^].

—SA
  Permalink  
Comments
Maciej Los 19-Jul-13 9:36am
   
String.Replace function... This is it!
+5!
   
Thank you, Maciej.
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi . i think the simplest way is :

string s=path.Substring(path.IndexOf('Y'),15);
in this line of code you get a substring by position of 'Y' character.
and the count of forwarding to get substring, is 15 character.
i hope this help you.
Good luck
  Permalink  
Comments
epanjohura 23-Jul-13 8:07am
   
I already have a solution but thanks for your help
ali rad 24-Jul-13 6:49am
   
you're wecolme.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 22 Jul 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100