正则表达式转换〜UNC到URL [英] Regular Expressions ~ convert UNC to URL

查看:108
本文介绍了正则表达式转换〜UNC到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找一个很好的紧正则表达式的解决这个问题。我期待重新格式化的UNC到一个URI

I'm looking for a nice tight regex solution to this problem. I'm looking to reformat an UNC into a Uri

问题:

UNC目录需要重新格式化成一个URI

UNC directory needs to be reformatted into a Uri

\\server\d $ \x\y\z\AAA

需要如下:

的http://服务器/ Z / AAA

http://server/z/AAA

推荐答案

我想更换更容易编写和理解比正则表达式在这种情况下。鉴于:

I think a replace is easier to write and understand than Regex in this case. Given:

string input = "\\\\server\\d$\\x\\y\\z\\AAA";

您可以做一个双替换:

string output = String.Format("http:{0}", input.Replace("\\d$\\x\\y", String.Empty).Replace("\\", "/"));

这篇关于正则表达式转换〜UNC到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆