如何检查字符串是否有效的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