使用 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. ESET NOD32 Antivirus – 免费 3个月/ 3PC

    ESET NOD32 Antivirus 3个月/ 3PC俄罗斯活动,3用户3个月免费,仅用于EAV,不能用于ESS活动地址: 点此进入申请方法:一共2封邮件,第2封含3个月许可

  2. 关于Predynastic Egypt

    游戏界面(资源增加工人,工人产生资源) 解锁建筑(花费资源增加某一地区产出) 神灵祭祀(献祭资源获得临时buff,如减少建筑时间,一定回合内减少入侵几率,增加粮食产出,减少消耗资源等) 解锁科技(增加 ...

  3. 查看Linux下系统资源占用常用命令

    一 top命令 1.作用top命令用来显示执行中的程序进程,使用权限是所有用户. 2.格式top [-] [d delay] [q] [c] [S] [s] [i] [n] 3.主要参数d:指定更新的 ...

  4. vue2.0分页组件,

    pagination.vue <!-- 表格分页组件 --> <template> <nav class="boot-nav"> <ul ...

  5. pip source

    linux版本 sudo vim .pip/pip.conf[global]index-url = http://pypi.douban.com/simple[install]trusted-host ...

  6. GET_DDL提取建表语句:ddl

    创建对象的语句就是了 提取表 set line 200 pages 50000 wrap on long 999999 serveroutput on SQL> select dbms_meta ...

  7. ODBC的基础架构

    *) 基本概念:1. 应用程序(Application)2. ODBC驱动管理器(ODBC Driver Manager) 负责管理应用程序和驱动程序间的通信,主要功能包括:解析DSN (数据源名称, ...

  8. GPIO口的输入输出模式

    1.浮空输入  GPIO_Mode_IN_FLOATING       2.带上拉输入  GPIO_Mode_IPU       3.带下拉输入  GPIO_Mode_IPD       4.模拟输入 ...

  9. [LeetCode&Python] Problem 693. Binary Number with Alternating Bits

    Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...

  10. HDU - 2475:Box(splay维护森林)

    There are N boxes on the ground, which are labeled by numbers from 1 to N. The boxes are magical, th ...