gpt4 book ai didi

c# - 从字符串 ascii 转换为字符串 Hex

转载 作者:可可西里 更新时间:2023-11-01 08:03:31 26 4
gpt4 key购买 nike

假设我有这个字符串

string str = "1234"

我需要一个将这个字符串转换成这个字符串的函数:

"0x31 0x32 0x33 0x34"  

网上查了很多类似的东西,都没有这个问题的答案。

最佳答案

string str = "1234";
char[] charValues = str.ToCharArray();
string hexOutput="";
foreach (char _eachChar in charValues )
{
// Get the integral value of the character.
int value = Convert.ToInt32(_eachChar);
// Convert the decimal value to a hexadecimal value in string form.
hexOutput += String.Format("{0:X}", value);
// to make output as your eg
// hexOutput +=" "+ String.Format("{0:X}", value);

}

//here is the HEX hexOutput
//use hexOutput

关于c# - 从字符串 ascii 转换为字符串 Hex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com