1

System.IO.Path.GetInvalidPathChars()無効な文字のリストを提供します。

しかし、私はすべての有効な文字のリストを持っている必要があります。

頭に浮かぶ最初の簡単なアイデアは、0から255まで繰り返し、無効な文字を除外することですが、有効な文字のみを提供しますか?また、Unicodeはどうですか?0から65535まで繰り返す必要がありますか?

4

2 に答える 2

1

これはどう:

    private static IEnumerable<char> GetValidFileNameChars()
    {
        var invalidChars = new List<char>(System.IO.Path.GetInvalidFileNameChars());
        var allChars = new List<char>();
        for (var i = 0; i < 255; i++)
        {
            allChars.Add((char) i);
        }

        var validChars = allChars.AsEnumerable().Except(invalidChars.AsEnumerable());
        return validChars;
    }

または、0 から 65535 (char.MinValueまでchar.MaxValue) まで繰り返すこともできます。

于 2013-06-13T09:46:39.407 に答える
1

私の知る限り、この情報を取得するための.NETには何もありません。

次の Microsoft ページを参照してください: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

関連する抜粋:

Use any character in the current code page for a name, including Unicode characters and characters
in the extended character set (128–255), except for the following:

    The following reserved characters:

        < (less than)  
        > (greater than)
        : (colon)
        " (double quote)
        / (forward slash)
        \ (backslash)
        | (vertical bar or pipe)
        ? (question mark)
        * (asterisk)

    Integer value zero, sometimes referred to as the ASCII NUL character.

    Characters whose integer representations are in the range from 1 through 31,
    except for alternate data streams where these characters are allowed.

    Any other character that the target file system does not allow.
于 2012-11-12T19:07:48.930 に答える