gpt4 book ai didi

c# - 用于文件名(在 Windows 上)和 URL 中的占位符的最佳字符是什么?

转载 作者:太空狗 更新时间:2023-10-30 00:58:05 24 4
gpt4 key购买 nike

我正在用 C# 编写一个应用程序,它需要在 URL 和/或文件名中查找占位符,并替换为一个值,就像这样:C:\files\file{number} = > C:\files\file1 不幸的是,对于该示例,文件名和 URL 中允许使用花括号。

谁能推荐一些我可以用来表示文件和 URL 中的占位符的字符?谢谢!

最佳答案

当您尝试使用其中的一个时,Windows 会很有帮助地告诉您文件名中不允许使用哪些字符:

A filename cannot contain any of the following characters:
\ / : * ? " < > |

参见 this support article了解更多信息,包括允许的字符列表。

Characters that are valid for naming files, folders, or shortcuts include any combination of letters (A-Z) and numbers (0-9), plus the following special characters:

^   Accent circumflex (caret)&   Ampersand'   Apostrophe (single quotation mark)@   At sign{   Brace left}   Brace right[   Bracket opening]   Bracket closing,   Comma$   Dollar sign=   Equal sign!   Exclamation point-   Hyphen#   Number sign(   Parenthesis opening)   Parenthesis closing%   Percent.   Period+   Plus~   Tilde_   Underscore

关于 URL,请参阅 RFC 1738 的第 2.2 节有关允许字符的描述:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

...同样感兴趣,来自同一部分:

Characters can be unsafe for a number of reasons. The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs. The characters "<" and ">" are unsafe because they are used as the delimiters around URLs in free text; the quote mark (""") is used to delimit URLs in some systems. The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a fragment/anchor identifier that might follow it. The character "%" is unsafe because it is used for encodings of other characters. Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`".

All unsafe characters must always be encoded within a URL.

看起来双引号和尖括号字符 ( "<> ) 是不错的选择。

关于c# - 用于文件名(在 Windows 上)和 URL 中的占位符的最佳字符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3696454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com