Scott Furr

Scott Furr

  • NA
  • 15
  • 0

Need help parsing a string

Dec 9 2008 2:55 PM

Hello all,

I have a quick question.  I'm trying to split a path into two separate variables but I can't find an efficient way of doing this.

   EX:  path = "C:\downloads\apps\test\test1.txt"

I want to be able to split the string so that I have path separated from file name.

   Desired Result:  path = "C:\downloads\apps\test"

                            file = "test1.txt"

The path will change so counting characters is not an option.  I worked with winbatch a LOOONG time ago and it had an option to start at the end of a string and work backwards to the first occurrence of a character ( \ ) and then split the string at that location.  Does C# have something like this?

I looked at string.parse but it's creating an array by splitting at EVERY instance of ( \ ).  Then you have to put it together the way you want.  There HAS to be an easier way unless I'm completely misunderstanding the way parse works.

Any help would be much appreciated!

 

Thanks!


Answers (1)