Есть черновик кода на С#, код работает отлично но вывод в MessageBox.Show выводит: �ݐ , а должен вывести строковую переменную t: �ݐyd��m���d��{��Y да, без проблем . В чём может быть проблема?
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
namespace WindowsFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
LoadSQLite();
}
private void LoadSQLite()
{
string ConSQLite = @"*************";
SQLiteConnection connection =
new SQLiteConnection(string.Format("Data Source={0};", ConSQLite));
connection.Open();
SQLiteDataAdapter adapter =
new SQLiteDataAdapter("*********************************", connection);
DataTable dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
SQLiteCommand com =
new SQLiteCommand("****получение hex***************", connection);
object result = com.ExecuteScalar();
string hex = Convert.ToString(result);
String hexs;
HexStringToString(hex, out hexs);
textBox1.Text = hex;//11DCDD900001000079000000649BA90E6DBCB19D649BA90E7BBCEE591BD0B4D0B02C20D0B1D0B5D0B720D0BFD180D0BED0B1D0BBD0B5D0BC00000000
string text = hexs; //"\u0011ЬЭђ\0\u0001\0\0y\0\0\0d›©\u000emј±ќd›©\u000e{јоY\u001bРґР°, без проблем\0\0\0\0";
Encoding utf8 = Encoding.GetEncoding("UTF-8");
Encoding win1251 = Encoding.GetEncoding("Windows-1251");
byte[] utf8Bytes = win1251.GetBytes(text);
var t = utf8.GetString(utf8Bytes);
MessageBox.Show(t, "utf8Bytes");
String hexc;
}
string HexStringToString(string hex, out string hexs)
{
var raw = new byte[hex.Length / 2];
for (int i = 0, j = 0; i < hex.Length; i += 2, j++)
raw[j] = Convert.ToByte(hex.Substring(i, 2), 16);
hexs = Encoding.GetEncoding(1251).GetString(raw);
return hexs;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}