zoukankan      html  css  js  c++  java
  • Path.Combine(string,string)

    有关Path.Combine()方法

    故名思义,其方法将两个字符串合并成一个合法的路径,

    如合并Application.StartupPath和一个文件名,将输出正常的文件路径

    但请注意,Application.StartupPath返回的路径并不包含"\",

    实际使用后将自动加上反斜杠,如下为源码,其中Path.AltDirectorySeparatorChar几个值在代码后有给出,记录下下


    public static string Combine(string path1, string path2)
    {
        
    if ((path1 == null|| (path2 == null))
        {
            
    throw new ArgumentNullException((path1 == null? "path1" : "path2");
        }
        CheckInvalidPathChars(path1);
        CheckInvalidPathChars(path2);
        
    if (path2.Length == 0)
        {
            
    return path1;
        }
        
    if (path1.Length == 0)
        {
            
    return path2;
        }
        
    if (IsPathRooted(path2))
        {
            
    return path2;
        }
        
    char ch = path1[path1.Length - 1];
        
    if (((ch != DirectorySeparatorChar) && (ch != AltDirectorySeparatorChar)) && (ch != VolumeSeparatorChar))
        {
            
    return (path1 + DirectorySeparatorChar + path2);
        }
        
    return (path1 + path2);
    }

    // Path.AltDirectorySeparatorChar=/
    // Path.DirectorySeparatorChar=\
    // Path.PathSeparator=;
    // Path.VolumeSeparatorChar=:



    ------------------------------------------
    除非特别声明,文章均为原创,版权与博客园共有,转载请保留出处
    BUY ME COFFEE
  • 相关阅读:
    0~n-1中缺失的数字
    仅仅反转字母
    字符串相加
    反转字符串&反转字符串中的元音字母
    python OrderedDict类&LRU缓存机制练习题
    协程greenlet、gevent、猴子补丁
    生产者与消费者(两个线程之间的通信---队列实现)
    jquery的on()
    Python之内置类型
    Python之比较运算符
  • 原文地址:https://www.cnblogs.com/kkun/p/1377826.html
Copyright © 2011-2022 走看看