如何在C#.net中将字节转换为字符串 [英] how to convert byte to string in C#.net

查看:72
本文介绍了如何在C#.net中将字节转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们以varbinary格式将word文件插入数据库中.
现在我们要检索单词文件,然后将varbinary格式转换为字符串.

在这里,我们使用的代码是:-

we insert the word files in database in varbinary format.
Now we want to retrieve the word files then we are converting the varbinary format to string.

Here we are using the code:-

string x = Encoding.ASCII.GetString(buffer).ToLower();


它仅适用于.doc文件.
当我们检索.docx文件时,它无法转换为字符串,并且结果没有得到.
检索
时如何将.docx文件从字节转换为字符串格式


It is working for .doc files only.
when we retrieve the .docx file it can''t convert to string and result is not getting.
How can we convert .docx file as byte to string format when we are retrieving

string str1 = System.Text.ASCIIEncoding.ASCII.GetString(value).


我尝试使用上面的代码


Iam trying with the above code
It is not working.

推荐答案

System.Text.Encoding enc = System.Text.Encoding.ASCII;
string myString = enc.GetString(myByteArray )


尝试使用

Try with the

byte [] dBytes = string str;
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
str = enc.GetString(dBytes);


这篇关于如何在C#.net中将字节转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆