Getting unicode string from its code - C#

后端 未结 3 789
梦谈多话
梦谈多话 2020-12-13 13:04

I know following is the way to use unicode in C#

string unicodeString = \"\\u0D15\";

In my situation, I will not get the character code (

3条回答
  •  囚心锁ツ
    2020-12-13 13:17

    Here's an NUnit test showing arul and Adrian's solution - note that one solution starts with input in a string, while with the other solution the input starts in just a char.

        [Test]
        public void testConvertFromUnicode()
        {
    
            char myValue = Char.Parse("\u0D15");
            Assert.AreEqual(3349, myValue);
    
            char unicodeChar = '\u0D15';
            string unicodeString = Char.ConvertFromUtf32(unicodeChar);
            Assert.AreEqual(1, unicodeString.Length);
            char[] charsInString = unicodeString.ToCharArray();
            Assert.AreEqual(1, charsInString.Count());
            Assert.AreEqual((int) '\u0D15', charsInString[0]);
        }
    

提交回复
热议问题