Convert from string ascii to string Hex

前端 未结 7 1063
既然无缘
既然无缘 2021-02-07 10:31

Suppose I have this string

string str = \"1234\"

I need a function that convert this string to this string:

\"0x31 0x32 0x33          


        
7条回答
  •  时光说笑
    2021-02-07 11:06

     [TestMethod]
        public void ToHex()
        {
            string str = "1234A";
            var result = str.Select(s =>  string.Format("0x{0:X2}", ((byte)s)));
    
           foreach (var item in result)
           {
               Debug.WriteLine(item);
           }
    
        }
    

提交回复
热议问题