如何找到与我的alt代码匹配的字符

时间:2018-05-15 11:15:52

标签: c# wpf

当我输入 Alt + 1 时,我会回来☺ 我想在代码中使用一些神奇的方法来获取字符串中的☺字符。

这样的事情:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value         
of Authorization header is formed correctly including the signature.
Content-Length: 686
Content-Type: application/xml
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 7a96deee-201e-00fc-78de-ec0ffc000000
x-ms-error-code: AuthenticationFailed
Date: Wed, 16 May 2018 06:22:35 GMT

<?xml version="1.0" encoding="utf-8"?><Error>    
<Code>AuthenticationFailed</Code><Message>Server failed to authenticate the 
request. Make sure the value of Authorization header is formed correctly 
including the signature.
RequestId:7a96deee-201e-00fc-78de-ec0ffc000000
Time:2018-05-16T06:22:36.0842958Z</Message><AuthenticationErrorDetail>The 
MAC signature found in the HTTP request 
'E9M4w8nHaBbAsgW3Qhf+u5nHipvmxMvLp09AFdaxYZg=' is not the same as any 
computed signature. Server used following string to sign: 'PUT


110

text/plain






x-ms-date:Wed, 16 May 2018 06:22:34 GMT
x-ms-version:2017-07-29
/storagekaren/dbstore/ddd.txt
comp:blocklist'.</AuthenticationErrorDetail></Error>

然后在富文本框中应该有:string smiley = AltCodes.GetAltCodeCharacter(1).ToString(); // Display the Smiley richTextBoxHappy.Text = smiley;

2 个答案:

答案 0 :(得分:3)

您可以使用Unicode Table (Decimal)查找代码,然后像这样使用它:

int i = 9786;
textBoxHappy.Text = ((char)i).ToString();

结果图片:

enter image description here

修改

当然,您可以创建自定义映射,例如某些Dictionary<string, int>(或您想要的任何自定义类型),并向其添加代码{ "smiley", 9786 },然后使用altCode["smiley"]

更新

或者使用enum

enum AltCodes
{
    Smiley = 9786,
    NextSmiley = 9787
}

并使用它:

textBoxHappy.Text = ((char)AltCodes.Smiley).ToString();

您甚至可以创建自定义解码器,然后在wpf TextBox内编写alt代码(通过按住alt并输入数字),单击“Decode”并将代码值设为{ {1}}例如:

int[]

和用法(点击事件或命令):

private int[] DecodeCharCode(string str) =>
    DecodeCharCode(str.ToArray());


private int[] DecodeCharCode(char[] chars)
{
    int[] result = new int[chars.Length];
    for (int i = 0; i < chars.Length; i++)
    {
        result[i] = (int)chars[i];
    }
    return result;
}

答案 1 :(得分:1)

There is a finite number of these.您只需创建Dictionary<int, string>即可存储所有这些内容:

IReadOnlyDictionary<int, string> altCodes = new Dictionary<int, string>() {
    {1, "☺"},
    {2, "\U0000263B"},
    // and so on...
};

并按如下方式访问:

altCodes[1]