gpt4 book ai didi

c# - 缩小文件路径以更易于阅读的功能

转载 作者:太空狗 更新时间:2023-10-29 22:05:20 25 4
gpt4 key购买 nike

C# 中有没有缩小文件路径的函数?

输入:“c:\users\Windows\Downloaded Program Files\Folder\Inside\example\file.txt”

输出:“c:\users\...\example\file.txt”

最佳答案

Nasreddine 的回答几乎是正确的。在您的情况下,只需指定 StringBuilder 大小:

[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
static extern bool PathCompactPathEx(
[Out] StringBuilder pszOut,
string szPath,
int cchMax,
int dwFlags);

static string PathShortener(string path, int length)
{
StringBuilder sb = new StringBuilder(length + 1);
PathCompactPathEx(sb, path, length, 0);
return sb.ToString();
}

关于c# - 缩小文件路径以更易于阅读的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8360360/

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