gpt4 book ai didi

c# - 如何从此字符串中提取子字符串?

转载 作者:行者123 更新时间:2023-11-30 13:15:21 26 4
gpt4 key购买 nike

我正在尝试提取 URL 末尾的字符串。示例:

C:\this\that\ExtractThisString.exe
^^^^^^^^^^^^^^^^^^^^^

我正在尝试从该字符串中获取 ExtractThisString.exe,但是它有未知数量的 \。我希望它基本上抓取 URL 并列出它末尾的任何内容。

最佳答案

使用 System.IO.Path 类的辅助方法。在你的情况下:

string fileName = Path.GetFileName(@"C:\this\that\ExtractThisString.exe");

只是为了好玩,如果你必须自己做,你应该开始搜索最后一个Path.DirectorySeparatorChar的索引。 . 如果这不是字符串中的最后一个字符,那么您可以使用 String.Substring 提取该索引之后的所有文本。

关于c# - 如何从此字符串中提取子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9831382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com