C# 字符串转十六进制字符串
逆操作见👉C#十六进制字符串转字符串
using System;
namespace DataTypeApplication
{
class Program
{
static void Main(string[] args)
{
string str = "https://space.bilibili.com/37911467?spm_id_from=333.1007.0.0";
string str1 = strToHexstr(str);
Console.WriteLine(str1);
}
private static string strToHexstr(string str)
{
char[] vs = str.ToCharArray();
string b = "";
byte[] c = new byte[str.Length];
for (int i = 0; i < str.Length; i++)
{
c[i] = (byte)vs[i];
}
foreach (byte c1 in c)
{
b += c1.ToString("X2");
b += " ";
}
return b;
}
}
}
结果👇