路径字符串中的子字符串 - C# [英] sub string from path string - C#

查看:96
本文介绍了路径字符串中的子字符串 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要从这条路径中获取粗体子串。



C: \\Workspaces \\ thisRequired \\Di \\DiDe \\\\\\ Debug



我怎样才能得到这个?

Hi,

I need to get the bold substring from this path.

C:\\Workspaces\\thisRequired\\Di\\DiDe\\bin\\Debug

How can I get this?

推荐答案

最简单的方法?

Easiest way?
string path = "C:\\Workspaces\\thisRequired\\Di\\DiDe\\bin\\Debug";
string[] parts = path.Split('\\');
if (parts.Length >= 3)
    {
    Console.WriteLine(parts[2]);
    }


您可以使用拆分 [ ^ ]函数将整个路径字符串切断为\\之间的子字符串,或者您可以使用 IndexOf [ ^ ]和子串 [ ^ ]用于查找并提取它。
You can either use the Split[^] function to chop the whole path string up into the substrings between "\\", or you can use the IndexOf[^] and Substring[^] functions to find it and extract it.


这篇关于路径字符串中的子字符串 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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