Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

c# - How to get a filename from a path?

I need some Regular expression experts for an extra hand. :)

I have different paths,different folders,different amount of folders.

My question:How do I get the last thing - the filename?

For example in the path:

C:acdefgh.ddj

How do I get "fgh.ddj" with regular expressions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need regex's, you can do it just like this, its a system.io helper function:

myfilename = Path.GetFileName(mypath);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...