使用 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. MyEclipse WebSphere开发教程:安装和更新WebSphere 6.1, JAX-WS, EJB 3.0(三)

    MyEclipse超值折扣 限量 100 套! 立即开抢>> [MyEclipse最新版下载] MyEclipse支持Java EE技术(如JAX-WS和EJB 3.0),它们以功能包的形 ...

  2. MyEclipse移动开发教程:设置所需配置的iOS应用(一)

    MyEclipse个人授权 折扣低至冰点!立即开抢>> [MyEclipse最新版下载] 一.iOS应用程序配置要求 这个进程需要四个需求数据文件: 证书签名请求(CSR)文件 证书签名请 ...

  3. 2.spring 学习

    1.spring简单工程搭建 http://www.cnblogs.com/yun965861480/p/6278193.html 2.spring数据源 http://www.cnblogs.com ...

  4. UI基础:UIScrollView、UIPageControl

    UIScrollView UIScrollView 是可以滚动的视图,UIView本身不能滚动,子类UIScrollView扩展了滚动方面的功能. UIScrollView 是所有滚动视图的基类.以后 ...

  5. magento小常识

    magento后台设置好产品分类及添加产品后前台没有显示出来:以下几个可能: 1.首先检查网店商城的Root Category 以 及跟目录下面的子目录设置是否有误,具体在目录->管理分类-&g ...

  6. 20155229 2016-2017-2 《Java程序设计》第五周学习总结

    20155229 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 第八章: Java中所有错误都会被打包为对象. 设计错误对象都继承自java.lang.Th ...

  7. PyCharm首次使用(Hell world!)

    作为PyCharm编辑器的起步,我们理所当然的先写一个Hello word,并运行它.(此文献给对IDE不熟悉的初学者) 1,新建一个项目 File --> New Project... 2,新 ...

  8. solr学习三(测试类,含普通与ExtractingRequestHandler测试)

    solr客户端基本是配置出来的,服务端可以对其进行测试,我使用的是solrj服务端. 如果初学solr,先使用普通的测试类: import java.io.IOException; import ja ...

  9. hive 创建orc表

    orc表 创建具备ACID及Transactions的表 这里的表需要具备下面几个条件:  1. 必须以 ORC 格式存储  2. 必须分 bucket,且不能 sort  3. 必须显式声明tran ...

  10. day43 数据库学习egon的博客 约束

    一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...