如何在'/'之前修剪单词? [英] How to trim words before '/'?
本文介绍了如何在'/'之前修剪单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在'/'之前修剪单词
这是我的输入:
string Path =D:/new/image.jpg)
我的出局将是:
string path = image.jpg
How to trim words before '/'
This is my input:
string Path = "D:/new/image.jpg")
My out will be:
string path=image.jpg
推荐答案
你不应该修剪任何东西。你正在提取部分路径;有.NET FCL API。这就是你需要的:
https://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v = vs.110).aspx [ ^ ]。
-SA
You should not trim anything. You are extracting part of the path; there is .NET FCL API for that. This is what you need:
https://msdn.microsoft.com/en-us/library/system.io.path.getfilename(v=vs.110).aspx[^].
—SA
您好,
Hi,
string path = "D:/new/image.jpg";
int pos = path.LastIndexOf("/") + 1;
Console.WriteLine(path.Substring(pos, path.Length - pos)); // prints "image.jpg"
>
你不会在这里修剪。修剪删除空格和其他字符。
您将使用string.indexOf
和字符串.substring
。
或者,您可以使用string.split
。
以下是一些例子 -
IndexOf [ ^ ]
SubString [ ^ ]
拆分 [ ^ ]
You will not trim here. Trim removes whitespaces and other characters.
You will usestring.indexOf
andstring.substring
.
Alternatively, you can usestring.split
.
Here are some examples -
IndexOf[^]
SubString[^]
Split[^]
这篇关于如何在'/'之前修剪单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文