c# - 获取特定字符之间的字符串

标签 c# string uwp

我有一个字符串:“https://mhnkp2.com/src/vid/pra/Tentang_Mata-Cerita_Boneka-Prasekolah.mp4”

我只想得到“Tentang_Mata-Cerita_Boneka-Prasekolah”

我尝试使用代码:

string path = "https:\/\/mhnkp2.com\/src\/vid\/pra\/Tentang_Mata-Cerita_Boneka-Prasekolah.mp4"
int start = path.IndexOf("/") + 5;
int end = path.IndexOf(".", start);
string result = path.Substring(start, end - start);

但结果只有“kp”。如何处理?

最佳答案

你可以使用

System.IO.Path.GetFileNameWithoutExtension("https://mhnkp2.com/src/vid/pra/Tentang_Mata-Cerita_Boneka-Prasekolah.mp4")

关于c# - 获取特定字符之间的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57372507/

相关文章:

uwp - UWP 中的 ReadOnly 属性

java - 当我发现自己是 "over-casting"时该怎么办?

java - 如何删除字符串中的单个字符(java)?

c# - 尝试在 Java 服务器上连接时 UWP 客户端套接字 block ( Release模式)

c# - 从 AssemblyInfo.cs 文件中读取版本号

python - 依赖性。关于加载在函数或类中使用的模块,指导我吗?

c# - 如何将 ListView 项与 UWP 模型外部的数据绑定(bind)?

c# - 验证失败,但无法在 DataGridView 中移除

c# - 在 Canvas 中居中图像

c# - 如何从数据库中获取谷歌地图用户的位置?