zoukankan      html  css  js  c++  java
  • 计算相对路径

    代码
     1         #region 计算相对路径
     2 
     3         /// <summary>
     4         /// 获取路径2相对于路径1的相对路径
     5         /// </summary>
     6         /// <param name="strPath1">路径1</param>
     7         /// <param name="strPath2">路径2</param>
     8         /// <returns>相对路径</returns>
     9         private string GetRelativePath(string strPath1, string strPath2)
    10         {
    11             //格式化字符串成标准的格式
    12 
    13             strPath1 = strPath1.Replace("//""\\");
    14             strPath1 = strPath1.Replace("/""\\");
    15             strPath1 = strPath1.Replace(@"\\""\\");
    16             strPath2 = strPath2.Replace("//""\\");
    17             strPath2 = strPath2.Replace("/""\\");
    18             strPath2 = strPath2.Replace(@"\\""\\");
    19             int intIndex = -1, intPos = strPath1.IndexOf('\\');
    20 
    21             /*以"\"为分界比较从开始处到第一个"\"处对两个地址进行比较,如果相同则扩展到
    22             下一个"\"处;直到比较出不同或第一个地址的结尾*/
    23 
    24             while (intPos >= 0)
    25             {
    26                 intPos++;
    27                 if (string.Compare(strPath1, 0, strPath2, 0, intPos, true!= 0break;
    28                 intIndex = intPos;
    29                 intPos = strPath1.IndexOf('\\', intPos);
    30             }
    31 
    32             /*如果从不是第一个"\"处开始有不同,则从最后一个发现有不同的"\"处开始将strPath2
    33             的后面部分赋值给自己,在strPath1的同一个位置开始望后计算每有一个"\"则在strPath2
    34             的前面加上一个"..\"(经过转义后就是"..\\")*/
    35 
    36             if (intIndex >= 0)
    37             {
    38                 strPath2 = strPath2.Substring(intIndex);
    39                 intPos = strPath1.IndexOf("\\", intIndex);
    40                 while (intPos >= 0)
    41                 {
    42                     strPath2 = "..\\" + strPath2;
    43                     intPos = strPath1.IndexOf("\\", intPos + 1);
    44                 }
    45             }
    46 
    47             //否则直接返回strPath2
    48             return strPath2;
    49         }
    50 
    51         #endregion
  • 相关阅读:
    mabatis的批量新增sql 初级的 初级的 初级的
    (批量更新)对多个符合条件的id做更新操作
    js中的 !! 和 ! 的区别
    js中===和==的区别
    select下拉框使用完毕后,重置按钮使其清空
    select下拉框的数据回显
    字符串拼串 能缓解我们的开发难度→!←(ε=(´ο`*)))唉,又是一个不知道该怎么写题目的随笔啊,头疼)
    select下拉框可以直接取list里的内容 不用非得转map (不得不承认我是个ZZ,这么简单的问题才反应过来,--^--)
    sql中某条件不为空,可能有的小祖宗会喷了,这还用总结?emmm,我渣,我觉得有一点意思对于第二种(土味)
    左查询left join on简单总结
  • 原文地址:https://www.cnblogs.com/kakaliush/p/1624692.html
Copyright © 2011-2022 走看看