如何使用子字符串删除字符串(fileName)的结尾? [英] How to remove end of string (fileName) using substring?

查看:64
本文介绍了如何使用子字符串删除字符串(fileName)的结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我必须使用Substring删除,但是我不知道该怎么做.我需要删除这样的字符串结尾

I know I must use Substring to remove, but I dont know how to do this. I need to remove end of string like this

来自

"C:\\Users\\myname\\Pictures\\shoeImage.jpg"

"C:\\Users\\myname\\Pictures"

推荐答案

在这种情况下,您应该使用FileInfo-

You should use FileInfo in such scenarios -

FileInfo info = new FileInfo("C:\\Users\\myname\\Pictures\\shoeImage.jpg");
string name = info.DirectoryName;

OR

Path.GetDirectoryName("C:\\Users\\myname\\Pictures\\shoeImage.jpg");

这篇关于如何使用子字符串删除字符串(fileName)的结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆