如何缩短存储在字符串中的路径 [英] How Can I Short A Path That Is Stored At A String
问题描述
如何在字符串中创建一个简短的路径?
这只是字符串可以做的其他事情的一个例子。
string test = xcopy c:\ test\test\test\\\
ame.bat d:\ test\test\test\hi.bat
我想要
string test = xcopy c :\..\ name.bat d:\..\\\.bat
其他例子
字符串测试=无论c:\ test \ test \ test \ name.bat无论如何
到
字符串测试=无论c:\..\\\ name.bat无论如何
其他示例
regedit.exe / e:D:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ Piriform\CCleaner
to
regedit.exe / e:一个D:\..\..\..\..\CCleaner.regHKEY_CURRENT_USER \...\\...\\CCleaner
at autoit我可以用
Func _shortstringpath($ data)
返回StringRegExpReplace($ data,'([^ \\] + \\)(?:[^ \\] + \\)*([^] +)', $ 1 ... \\ $ 2)
EndFunc
i希望在c#2.0中执行此操作
这是自动代码问题的链接,但现在我需要它在c#
https://www.autoitscript.com/forum/topic/166301-short-path-anywhere-at-the-string/ [ ^ ]
data)
返回StringRegExpReplace(
数据, '([^ \\] + \\)(?:[^ \\] + \\)*([^] +)',
1 ... \\
How can i make a path short in a string?
This is just a example the string can something else.
string test = "xcopy c:\test\test\test\name.bat d:\test\test\test\hi.bat"
and i want to have
string test = "xcopy c:\..\name.bat d:\..\hi.bat"
other example
string test = "whatever c:\test\test\test\name.bat whatever"
to
string test = "whatever c:\..\name.bat whatever"
other example
regedit.exe /e:a "D:\data\backup\laptop\CCleaner\CCleaner.reg" "HKEY_CURRENT_USER\Software\Piriform\CCleaner"
to
regedit.exe /e:a "D:\..\..\..\..\CCleaner.reg" "HKEY_CURRENT_USER\..\..\CCleaner"
at autoit i can do this with
Func _shortstringpath($data)
Return StringRegExpReplace($data, '("[^\\]+\\)(?:[^\\"]+\\)*([^"]+")', "$1...\\$2")
EndFunc
i want to do this in c# 2.0
this is the link with the question for autoit code but now i need it in c#
https://www.autoitscript.com/forum/topic/166301-short-path-anywhere-at-the-string/[^]
data)
Return StringRegExpReplace(
data, '("[^\\]+\\)(?:[^\\"]+\\)*([^"]+")', "
1...\\
这篇关于如何缩短存储在字符串中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!