日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

C#-计算相对路径

發(fā)布時(shí)間:2023/12/18 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#-计算相对路径 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C#-計(jì)算相對(duì)路徑


???/**////?<summary>
????????
///?計(jì)算相對(duì)路徑
????????
///?后者相對(duì)前者的路徑。
????????
///?</summary>
????????
///?<param?name="mainDir">主目錄</param>
????????
///?<param?name="fullFilePath">文件的絕對(duì)路徑</param>
????????
///?<returns>fullFilePath相對(duì)于mainDir的路徑</returns>
????????
///?<example>
????????
///?@"..\..\regedit.exe"?=?GetRelativePath(@"D:\Windows\Web\Wallpaper\",?@"D:\Windows\regedit.exe"?);
????????
///?</example>

????????public?static?string?GetRelativePath(string?mainDir,?string?fullFilePath)
????????
{
????????????
if?(!mainDir.EndsWith("\\"))
????????????
{
????????????????mainDir?
+=?"\\";?
????????????}


????????????
int?intIndex?=?-1,?intPos?=?mainDir.IndexOf('\\');
??????????
????????????
while?(intPos?>=?0)
????????????
{
????????????????intPos
++;
????????????????
if?(string.Compare(mainDir,?0,?fullFilePath,?0,?intPos,?true)?!=?0)?break;
????????????????intIndex?
=?intPos;
????????????????intPos?
=?mainDir.IndexOf('\\',?intPos);
????????????}


??????????????
if?(intIndex?>=?0)
????????????
{
????????????????fullFilePath?
=?fullFilePath.Substring(intIndex);
????????????????intPos?
=?mainDir.IndexOf("\\",?intIndex);
????????????????
while?(intPos?>=?0)
????????????????
{
????????????????????fullFilePath?
=?"..\\"?+?fullFilePath;
????????????????????intPos?
=?mainDir.IndexOf("\\",?intPos?+?1);
????????????????}

????????????}

???????????
????????????
return?fullFilePath;
????????}


轉(zhuǎn)載于:https://www.cnblogs.com/ClarkChan/archive/2008/07/20/1247134.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的C#-计算相对路径的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。