- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我只是在使用这个最有用的链接:How do I check if a given string is a legal / valid file name under Windows?
在一些验证代码中我有一些看起来像的东西(忽略我没有使用 StringBuilder 类的事实并忽略形成消息时的错误(不需要多次告诉他们关于“冒号”的信息如果它多次出现在字符串中)):
string InvalidFileNameChars = new string(Path.GetInvalidFileNameChars());
Regex ContainsABadChar = new Regex("[" + Regex.Escape(InvalidFileNameChars) + "]");
MatchCollection BadChars = ContainsABadChar.Matches(txtFileName.Text);
if (BadChars.Count > 0)
{
string Msg = "The following invalid characters were detected:\r\n\r\n";
foreach (Match Bad in BadChars)
{
Msg += Bad.Value + "\r\n";
}
MessageBox.Show(Msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox 看起来像(使用找到冒号的示例):
-- 开始--
检测到以下无效字符:
:
-- 结束--
我希望它说这样的话:
-- 开始--
检测到以下无效字符:
冒号 -> :
-- 结束--
我喜欢英文名。不是 killer ,但很好奇是否有一些功能,比如(Char 类不存在,但可能存在于我没有想到的其他类中):
Char.GetEnglishName(':');
最佳答案
您可以只使用 basic latin and controls unicode block如果您永远不需要考虑每个字符。
您可以将表定义为一个简单的字符串数组以加快查找速度:
string[] lookup = new string[128];
lookup[0x00]="Null character";
lookup[0x01]="Start of Heading";
lookup[0x02]="Start of Text";
lookup[0x03]="End-of-text character";
lookup[0x04]="End-of-transmission character";
lookup[0x05]="Enquiry character";
lookup[0x06]="Acknowledge character";
lookup[0x07]="Bell character";
lookup[0x08]="Backspace";
lookup[0x09]="Horizontal tab";
lookup[0x0A]="Line feed";
lookup[0x0B]="Vertical tab";
lookup[0x0C]="Form feed";
lookup[0x0D]="Carriage return";
lookup[0x0E]="Shift Out";
lookup[0x0F]="Shift In";
lookup[0x10]="Data Link Escape";
lookup[0x11]="Device Control 1";
lookup[0x12]="Device Control 2";
lookup[0x13]="Device Control 3";
lookup[0x14]="Device Control 4";
lookup[0x15]="Negative-acknowledge character";
lookup[0x16]="Synchronous Idle";
lookup[0x17]="End of Transmission Block";
lookup[0x18]="Cancel character";
lookup[0x19]="End of Medium";
lookup[0x1A]="Substitute character";
lookup[0x1B]="Escape character";
lookup[0x1C]="File Separator";
lookup[0x1D]="Group Separator";
lookup[0x1E]="Record Separator";
lookup[0x1F]="Unit Separator";
lookup[0x20]="Space";
lookup[0x21]="Exclamation mark";
lookup[0x22]="Quotation mark";
lookup[0x23]="Number sign";
lookup[0x24]="Dollar sign";
lookup[0x25]="Percent sign";
lookup[0x26]="Ampersand";
lookup[0x27]="Apostrophe";
lookup[0x28]="Left parenthesis";
lookup[0x29]="Right parenthesis";
lookup[0x2A]="Asterisk";
lookup[0x2B]="Plus sign";
lookup[0x2C]="Comma";
lookup[0x2D]="Hyphen-minus";
lookup[0x2E]="Full stop";
lookup[0x2F]="Slash";
lookup[0x30]="Digit Zero";
lookup[0x31]="Digit One";
lookup[0x32]="Digit Two";
lookup[0x33]="Digit Three";
lookup[0x34]="Digit Four";
lookup[0x35]="Digit Five";
lookup[0x36]="Digit Six";
lookup[0x37]="Digit Seven";
lookup[0x38]="Digit Eight";
lookup[0x39]="Digit Nine";
lookup[0x3A]="Colon";
lookup[0x3B]="Semicolon";
lookup[0x3C]="Less-than sign";
lookup[0x3D]="Equal sign";
lookup[0x3E]="Greater-than sign";
lookup[0x3F]="Question mark";
lookup[0x40]="At sign";
lookup[0x41]="Latin Capital letter A";
lookup[0x42]="Latin Capital letter B";
lookup[0x43]="Latin Capital letter C";
lookup[0x44]="Latin Capital letter D";
lookup[0x45]="Latin Capital letter E";
lookup[0x46]="Latin Capital letter F";
lookup[0x47]="Latin Capital letter G";
lookup[0x48]="Latin Capital letter H";
lookup[0x49]="Latin Capital letter I";
lookup[0x4A]="Latin Capital letter J";
lookup[0x4B]="Latin Capital letter K";
lookup[0x4C]="Latin Capital letter L";
lookup[0x4D]="Latin Capital letter M";
lookup[0x4E]="Latin Capital letter N";
lookup[0x4F]="Latin Capital letter O";
lookup[0x50]="Latin Capital letter P";
lookup[0x51]="Latin Capital letter Q";
lookup[0x52]="Latin Capital letter R";
lookup[0x53]="Latin Capital letter S";
lookup[0x54]="Latin Capital letter T";
lookup[0x55]="Latin Capital letter U";
lookup[0x56]="Latin Capital letter V";
lookup[0x57]="Latin Capital letter W";
lookup[0x58]="Latin Capital letter X";
lookup[0x59]="Latin Capital letter Y";
lookup[0x5A]="Latin Capital letter Z";
lookup[0x5B]="Left Square Bracket";
lookup[0x5C]="Backslash";
lookup[0x5D]="Right Square Bracket";
lookup[0x5E]="Circumflex accent";
lookup[0x5F]="Low line";
lookup[0x60]="Grave accent";
lookup[0x61]="Latin Small Letter A";
lookup[0x62]="Latin Small Letter B";
lookup[0x63]="Latin Small Letter C";
lookup[0x64]="Latin Small Letter D";
lookup[0x65]="Latin Small Letter E";
lookup[0x66]="Latin Small Letter F";
lookup[0x67]="Latin Small Letter G";
lookup[0x68]="Latin Small Letter H";
lookup[0x69]="Latin Small Letter I";
lookup[0x6A]="Latin Small Letter J";
lookup[0x6B]="Latin Small Letter K";
lookup[0x6C]="Latin Small Letter L";
lookup[0x6D]="Latin Small Letter M";
lookup[0x6E]="Latin Small Letter N";
lookup[0x6F]="Latin Small Letter O";
lookup[0x70]="Latin Small Letter P";
lookup[0x71]="Latin Small Letter Q";
lookup[0x72]="Latin Small Letter R";
lookup[0x73]="Latin Small Letter S";
lookup[0x74]="Latin Small Letter T";
lookup[0x75]="Latin Small Letter U";
lookup[0x76]="Latin Small Letter V";
lookup[0x77]="Latin Small Letter W";
lookup[0x78]="Latin Small Letter X";
lookup[0x79]="Latin Small Letter Y";
lookup[0x7A]="Latin Small Letter Z";
lookup[0x7B]="Left Curly Bracket";
lookup[0x7C]="Vertical bar";
lookup[0x7D]="Right Curly Bracket";
lookup[0x7E]="Tilde";
lookup[0x7F]="Delete";
那么,您需要做的就是:
var englishName = lookup[(int)'~'];
或者:
public static string ToEnglishName(this char c)
{
int i = (int)c;
if( i < lookup.Length )
return lookup[i];
return "Unknown";
}
var name = ':'.ToEnglishName(); // Colon
关于c# - 如何获得角色的 "English name"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8931323/
我正在为我的雇主编写脚本,以从他们自己的站点获取某些数据。出于一长串原因,我需要从网站上获取数据,如图所示。我发现,其中一些数据是通过 js 调用检索的... 回想起来,我应该选择 Mechanize
我正在使用 python 和 cryptography.io 来签署和验证消息。我可以通过以下方式获得签名的 DER 编码字节表示: cryptography_priv_key.sign(messag
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
是否可以区分 ECDF?以下面得到的为例。 set.seed(1) a <- sort(rnorm(100)) b <- ecdf(a) plot(b) 我想对 b 求导以获得它的概率密度函数 (PD
我找到了如何从 navigator.mimeTypes 获取 mimetypes: function GetMimeTypes() { var message = ""; var mi
我在表单中使用单选按钮来隐藏/显示联系人表单中的成员 ID 字段。问题是,当 javascript 更改 html 中包含的隐藏 id 字段(该字段设置为“无”值)时,该字段将不再通过 post 可用
我正在做单元测试。我必须测试所有可能的if..else情况。但是在此if语句中: int32_t i32Res = snprintf(buffer, len, "The%d_String_%d", 0
我有一个 Facebook 应用程序,我想从中获取“喜欢”的总数。我想知道这是否可能。 其中 ID 是应用程序的 ID,ACCESS_TOKEN 是我尝试过的应用程序的当前访问 token : gra
如果我有多个计算实例尝试同时获取同一个 blob 的租约,则似乎经常会成功。我的印象是,一旦租约发出(并因此被客户获得),就不可能同时发出另一个租约? 我希望情况确实如此,我一直在 Azure 中使用
这是我的索引 POST /blogs/1 { "name" : "learn java", "popularity" : 100 } POST /blogs/2 { "name" : "l
我正在将 Symfony2 与 FOSUserBundle 一起使用。我需要为用户获得最高角色。 role_hierarchy: ROLE_CONTRIBUTOR: ROLE_USER
我正在向服务器发送基于 REST 的请求。我希望尽快得到答复,并希望了解可以进行的各种优化。 一种方法当然是在线程中并行发送这些请求。还有哪些其他选项可用于优化此功能? 在服务器上,可以添加哪些配置?
这可能是某种重复的问题,但我似乎找不到合适的解决方案。我正在使用 git4idea.history.GitHistoryUtils.history() 获取提交列表。如果 checkout 其中一个较
我正在做一个程序,可以输入每周的工资和那一周的总工作时间。它应该以小时工资率显示答案。但是我无法显示正确的“centavos/2 decimal places”公式并且它不想使用 float % fl
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我已经尝试了 mContext.getMainLooper() 和 Looper.getMainLooper()。两者都返回相同的结果,但我想知道哪种方法正确? 我还从 Android 开发人员链接中
我有一个“affiliates”表,其中包含“user”和“referredBy”列。 给定一个用户,我希望获得该用户推荐的所有“n 级”玩家。对于 n=1,我们只关心您直接推荐的玩家数量: SELE
我在 PostgreSQL 9.5 数据库中有两个表: project - id - name task - id - project_id - name - updated_
请帮助我怎样才能得到我预期的结果,在此先感谢并抱歉我的英语不好。 PHP: $dog = implode(',', $data['dogbreed']); $query .= "AND `do
我有 let impulse = CGVectorMake(CGFloat(Constants.impulse), 0) 如何在不创建另一个 CGVector 的情况下得到它的负值? 我正在考虑在 C
我是一名优秀的程序员,十分优秀!