Convert from string ascii to string Hex

前端 未结 7 1091
既然无缘
既然无缘 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 10:50

    A nice declarative way to solve this would be:

    var str = "1234"
    
    string.Join(" ", str.Select(c => $"0x{(int)c:X}"))
    
    // Outputs "0x31 0x32 0x33 0x34"
    

提交回复
热议问题