byte[] bytes = new byte[3];
bytes[0] = 83;
bytes[1] = 72;
bytes[2] = 0x00;
String str = new String(bytes);
String str1 = str + "1234567";
这段代码就是得不到我想要的结果,str1就是不对,怎么办呀
------解决方案--------------------------------------------------------
up
------解决方案--------------------------------------------------------
你这代码得到的结果是什么?
你想要的结果是什么?
------解决方案--------------------------------------------------------
你得到的String应该是UTF编码的,如果你需要的是ASCII的,请用System.Text的Encoding类转换。
------解决方案--------------------------------------------------------
需要将数组转换为unicode 字符的数组。
------解决方案--------------------------------------------------------
string a="askdjfa;ldksfjwilgfj";
char[] c=a.ToCharArray();
------解决方案--------------------------------------------------------
//命名空间
using System.Text;
//转string
byte[] Name = new byte[100];
string strName="asd";
ASCIIEncoding st = new ASCIIEncoding();
strName = st.GetString(Name);
//转byte[]
byte[] Name;
string sName = "Group1";
ASCIIEncoding st = new ASCIIEncoding();
Name = st.GetBytes(sName);
------解决方案--------------------------------------------------------
byte[] bytOut = {....};
string Result = System.Text.Convert.ToBase64String(bytOut);
------解决方案--------------------------------------------------------
是编码类型问题
------解决方案--------------------------------------------------------
msdn的源码
using System;
using System.Text;
namespace ConvertExample
{
class ConvertExampleClass
{
static void Main()
{
string unicodeString = "This string contains the unicode character Pi(\u03a0)";
// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];