String and Path

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am trying to create a few String extensions that given a path, for
example:

"Contents/Image/FileName.jpg"

It provides the Path, FileName and Extension.

For example:

String fullPath = "Contents/Image/FileName.jpg";

1. String path = fullPath.GetPath();
Would return "Contents/Image/"

2. String filename = fullPath.GetFileName();
Would return "FileName"

3. String extension = fullPath.GetExtension();
Would return "jpg"

My problem is the string part not the extension creating.

How can I do this? And should I use Regex?

Thanks,
Miguel
 
Hello,

I am trying to create a few String extensions that given a path, for
example:

"Contents/Image/FileName.jpg"

It provides the Path, FileName and Extension.

For example:

String fullPath = "Contents/Image/FileName.jpg";

1. String path = fullPath.GetPath();
    Would return "Contents/Image/"

2. String filename = fullPath.GetFileName();
     Would return "FileName"

3. String extension = fullPath.GetExtension();
     Would return "jpg"

My problem is the string part not the extension creating.

How can I do this? And should I use Regex?

Thanks,
Miguel

Forget it ... I will use:

Path.GetPathRoot()
Path.GetFileName()
Path.GetExtension()

Thanks,
Miguel
 
shapper said:
Hello,

I am trying to create a few String extensions that given a path, for
example:

"Contents/Image/FileName.jpg"

It provides the Path, FileName and Extension.

For example:

String fullPath = "Contents/Image/FileName.jpg";

1. String path = fullPath.GetPath();
Would return "Contents/Image/"

2. String filename = fullPath.GetFileName();
Would return "FileName"

3. String extension = fullPath.GetExtension();
Would return "jpg"

My problem is the string part not the extension creating.

How can I do this? And should I use Regex?

Thanks,
Miguel

Hi,

The Path class already has functionality like what You need.
( http://msdn.microsoft.com/en-us/library/system.io.path.aspx )

Hope You find this useful.
-Zsolt
 
Back
Top