[原]System.IO.Path.Combine 路径合并
使用 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 路径合并的更多相关文章
- 使用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)函数进行路径生成 明明是 ...
- System.IO.Path文件路径类
Path类的静态属性和方法,此类操作不影响物料文件. 属性 char a = System.IO.Path.VolumeSeparatorChar;//: char b = System.IO.Pat ...
- System.IO.Path类
System.IO.Path为路径的操作封装了很多很有的东西,利用该类提供的方法能够快速处理路径操作的问题.下面详细了解一下. 1.属性 属性太复杂了,反映什么系统平台的信息,看不懂,等以后看得懂了再 ...
- C#使用System.IO.Path获取文件路径、文件名
class Program { static void Main(string[] args) { //获取当前运行程序的目录 string fileDir = Environment.Current ...
- System.IO.Path 文件名、路径、扩展名 处理
string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...
- System.IO.Path 文件名、路径、扩展名处理
string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...
- C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)
一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...
- System.IO.Path
System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...
- System.IO.Path 操作
System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...
随机推荐
- 软工作业No.4
2048小游戏—设计开发 软件需求规格说明书 甜美女孩 2018年10月 ——————————————————————————— 文档修改记录 日期 版本 说明 作者 2018-10-18 V1. ...
- git add && git add -u && git add -A
git add将当前工作目录中更改或者新增的文件加入到Git的索引中,加入到Git的索引中就表示记入了版本历史中,这也是提交之前所需要执行的一步.可以递归添加,即如果后面跟的是一个目录作为参数,则会递 ...
- ADB命令行工具使用
Putty工具连接Android设备 下载链接:https://github.com/sztupy/adbputty/downloads 如上图所示:在HostName中输入transport-usb ...
- Netty网络聊天室之会话管理
写过web的同学们应该对Session这个东西很熟悉.浏览器第一次与服务器建立连接的时候,服务器就会自动为之分配一个Session.Session可以用来判断用户是否经过登录验证,也可以保存用户的各种 ...
- Spring学习(二)--IOC
一.什么是IOC? 孤傲苍狼总结的理解: https://www.cnblogs.com/xdp-gacl/p/4249939.html 我的理解(不知道对不对哈,不对的话请各位大神指出): IOC往 ...
- Object-C 基础笔记4---ARC内存管理
内存管理的原则 1,对你自己拥有的对象负责.你只能释放自己拥有的对象.(谁污染谁治理). 2,凡是通过retain,alloc,copy等于段获得了所有权对象,都必须在你不再使用的时候释放.调用rel ...
- 如何使用 python3 将RGB 图片转换为 灰度图
首先,介绍第一种方法, 使用 PIL 库, PIL库是一种python语言常用的一个图形处理库. 关于 PIL 库的安装本文就不介绍了. from PIL import Image I ...
- Ubuntu16.04 和 hadoop2.7.3环境下 hive2.1.1安装部署
参考文献: http://blog.csdn.NET/reesun/article/details/8556078 http://blog.csdn.Net/zhongguozhichuang/art ...
- linux下sprintf_s函数的替代
error code: ]; sprintf_s(buf, , "predicted position:(%3d, %3d)", predict_pt.x, predict_pt. ...
- 响应式有利于SEO还是pc+手机端分开url有利于SEO?
一早上都在查这个问题,大家都来讨论一下. 首先,可以肯定的是,如果公司推广重在谷歌,要做响应式.但是对于百度推广呢??虽然响应式是趋势,但是目前而言,对于百度怎样好呢