110,534
社区成员
发帖
与我相关
我的任务
分享
byte[] array = new byte[s.Length / 2];
for (int i = 0; i < s.Length / 2; i++)
{
string str = s.Substring(i, 2);
array[i] =(byte)Convert.ToInt32(str ,16);;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "4e135bb679f08fd1671f6c146e294ee5504f4f4e4e3a4e3bff0c662f5426201c5bd251ac201d4e0d80fd786e5b9a";
byte[] bytes = Regex.Matches(s, "[0-9a-fA-F]{2}").Cast<Match>().Select(x => (byte)Convert.ToInt16("0x" + x.Value, 16)).ToArray();
var result1 = System.Text.UnicodeEncoding.BigEndianUnicode.GetString(bytes, 0, bytes.Length);
Console.WriteLine(result1);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] b = System.Text.Encoding.BigEndianUnicode.GetBytes("专家称近期气温以偏低为主,是否“寒冬”不能确定");
Console.WriteLine(string.Join("", b.Select(x => x.ToString("x").PadLeft(2, '0'))));
}
}
}
4e135bb679f08fd1671f6c146e294ee5504f4f4e4e3a4e3bff0c662f5426201c5bd251ac201d4e0d
80fd786e5b9a
Press any key to continue . . .