如何检查字符串是否有效的Unix路径 [英] How to check if string is valid unix path

查看:89
本文介绍了如何检查字符串是否有效的Unix路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用不带单声道的c#检查字符串是否有效(没有无效的字符)Unix路径?

How to check if string is valid(doesn''t have invalid chars) unix path using c# without mono?

推荐答案

首先,您需要弄清楚系统中有效字符和最大允许文件长度的子集.从此处开始: http://en.wikipedia.org/wiki/Filename [ http://msdn.microsoft.com/en-us/library/system. text.regularexpressions.regex.aspx [ ^ ].
http://en.wikipedia.org/wiki/Regular_expression [
—SA
First you need to figure out the sub-set of valid characters and maximum allowed file length in the system. Start here: http://en.wikipedia.org/wiki/Filename[^].

I would first check up the length and then validate the sequence using Regular Expressions, see:
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^].
http://en.wikipedia.org/wiki/Regular_expression[^].

This is easy but would need some time to put it right. For example, you can have ''.'' or ''..'' in combinations with ''/'' or file name characters. (This is all true for Windows, but there are many people who incorrectly think it is not.)

—SA


这篇关于如何检查字符串是否有效的Unix路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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