使用 ILSpy 工具查看了 System.IO.Path 类中的 Combine 方法

对它的功能有点不放心,原方法实现如下:

// System.IO.Path
/// <summary>Combines two path strings.</summary>
/// <returns>A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If <paramref name="path2" /> contains an absolute path, this method returns <paramref name="path2" />.</returns>
/// <param name="path1">The first path. </param>
/// <param name="path2">The second path. </param>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="path1" /> or <paramref name="path2" /> contain one or more of the invalid characters defined in <see cref="M:System.IO.Path.GetInvalidPathChars" />. </exception>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="path1" /> or <paramref name="path2" /> is null. </exception>
/// <filterpriority></filterpriority>
public static string Combine(string path1, string path2)
{
if (path1 == null || path2 == null)
{
throw new ArgumentNullException((path1 == null) ? "path1" : "path2");
}
Path.CheckInvalidPathChars(path1);
Path.CheckInvalidPathChars(path2);
if (path2.Length == )
{
return path1;
}
if (path1.Length == )
{
return path2;
}
if (Path.IsPathRooted(path2))
{
return path2;
}
char c = path1[path1.Length - ];
// if (c != '\\' && c != '/' && c != ':')
if (c != Path.DirectorySeparatorChar && c != Path.AltDirectorySeparatorChar && c != Path.VolumeSeparatorChar)
{
// return path1 + '\\' + path2;
return path1 + Path.DirectorySeparatorChar + path2;
}
return path1 + path2;
}

方法中合并文件路径没问题 C:\\\\123.txt 但若是合并网址就会像这样 http://www.baidu.com\\search

提外话: 这路径在 谷歌浏览器 和 IE10 都被正确识别为 http://www.baidu.com/search

但还是觉得不够完美

[原]System.IO.Path.Combine 路径合并的更多相关文章

  1. 使用System.IO.Combine(string path1, string path2, string path3)四个参数的重载函数提示`System.IO.Path.Combine(string, string, string, string)' is inaccessible due to its protection level

    今天用Unity5.5.1开发提取Assets目录的模块,使用时采用System.IO.Path.Combine(string, string, string, string)函数进行路径生成 明明是 ...

  2. System.IO.Path文件路径类

    Path类的静态属性和方法,此类操作不影响物料文件. 属性 char a = System.IO.Path.VolumeSeparatorChar;//: char b = System.IO.Pat ...

  3. System.IO.Path类

    System.IO.Path为路径的操作封装了很多很有的东西,利用该类提供的方法能够快速处理路径操作的问题.下面详细了解一下. 1.属性 属性太复杂了,反映什么系统平台的信息,看不懂,等以后看得懂了再 ...

  4. C#使用System.IO.Path获取文件路径、文件名

    class Program { static void Main(string[] args) { //获取当前运行程序的目录 string fileDir = Environment.Current ...

  5. System.IO.Path 文件名、路径、扩展名 处理

    string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...

  6. System.IO.Path 文件名、路径、扩展名处理

    string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...

  7. C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)

    一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...

  8. System.IO.Path

    System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...

  9. System.IO.Path 操作

    System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...

随机推荐

  1. python爬虫田康林

       代码如下 import requestsimport json import time import os from threading import Timer def getHTML(url ...

  2. DevExpress v17.2新版亮点—WPF篇(二)

    用户界面套包DevExpress v17.2终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WPF v17.2 新的Hamburger Menu.Sched ...

  3. String,StringBuilder和StringBuffer的特点和使用场景

    这三个类是平时开发中经常遇到的,主要差别是运行速度和线程安全,使用起来String最方便了,另外两个稍微复杂一些. 从运行速度角度看,StringBuilder>StringBuffer> ...

  4. Centos7 安装 MySQL5.7

    Centos7 安装 MySQL5.7 一.环境介绍 1.安装包版本介绍 MySQL 有三种安装方式:RPM安装.二进制包安装.源码包安装.我们这篇文章以二进制方式安装MySQL 软件名称 版本 系统 ...

  5. Boosting 简单介绍

    前面介绍了Adaboost,知道了Adaboost是损失函数为指数函数的Boosting算法.那么Boosting还包括了以下几个: 损失函数名称 损失函数 算法 平方差(Squared error) ...

  6. VC++实现解析快捷方式

    VC++实现解析快捷方式: http://blog.csdn.net/mydreamremindme/article/details/9826745 

  7. Use JAWS 14 in a VM

    We were not able to run the JAWS 14 app in a Virtual Machine after the installation is completed, th ...

  8. ajax完整请求

    @RequestMapping(value = "/quotaPage") // , method = RequestMethod.GET名额分配@ResponseBody //注 ...

  9. 使用webpack搭建vue项目中遇到的问题

    1:data数据文件经试验,需要放在生成的build文件夹中才能生效,但是应该把data文件夹先放在src中,然后如何定义config文件,让其复制过去? new CopyWebpackPlugin( ...

  10. 详解Hadoop Slots的含义

    Slots是Hadoop的一个重要概念.然而在Hadoop相关论文,slots的阐述难以理解.网上关于slots的概念介绍也很少,而对于一个有经验的Hadoop开发者来说,他们可能脑子里已经理解了sl ...