如何把string转换为char[]以及byte[],两种代码都要
解决方案 »
- 怎么做出一个登录数据库的界面?
- Winform子窗体在移动时如何控制不能超出MDI窗体范围
- 大家帮我看一段代码~~这段提示的错误是 未将对象引用设置到对象的实例
- WindowsMediaPlayer控件
- c# 寻找xml文件中满足某属性的结点
- (在线等待) C#中一个简单的问题.(服务器,客户端).....急急急......
- 求购一段日历脚本,能同时在ie和friefox下运行的!!!!
- 100分!c# 怎样得到Api函数的指针的指针F(void **V)
- 怎样在留言板中添加qq表情啊?我是初学者哈,要代码的哈,详细点哈
- Application.StartupPath + @"\wcy.mdb"
- 急切请教:如何得到光标所在的控件?
- ACCESS 能新增记录但不能删除记录的问题!急
char [] ch = str.ToCharArray();foreach(char temp in ch)
{
Console.WriteLine(temp);
}
byte[] a=new byte[0];
a=(byte[])str;
不知道行不行,没测试的
byte[] a = new UTF8Encoding(true).GetBytes(s);
这个可以不
1。
字符串转换为字节数组,你需要指定编码,不同的编码,输出的字节数组是不一样的,
同时,读取的时候,也要使用对应的编码,否则非拉丁字符会乱出现乱码string str = "hello world";
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(str);
char[] chars = System.Text.Encoding.UTF8.GetChars(buffer);
chars = str.ToCharArray(); // 此方法内部使用 Unicode 编码
// byte[] buffer = System.Text.Encoding.GetEncode("GB2312").GetBytes(str);
//char[] chars = (char[])buffer; // CS0030: 无法将类型“byte[]”转换为“char[]”
chars = new char[buffer.Length];
Array.Copy(buffer, chars, buffer.Length); // 直接拷贝隐式转换2。
事实上,如果你进行写字符串,可以选择 StreamWriterstring str = "hello world";
using(System.IO.FileStream fstream = new System.IO.FileStream("C:\\somefile")) {
System.IO.StreamWriter writer = new System.IO.StreamWriter(fstream);
writer.Write(str);
}
byte[] inputBytes =converter.GetBytes(inputString);
string inputString = converter.GetString(inputBytes);
Encoding.ASCII.GetString(inputBytes,0,inputBytes.Length)); Encoding.ASCII.GetByte(Encoding.ASCII.GetString();
欢迎加入 C#学习QQ群 572453
char [] ch = str.ToCharArray();
byte[] buffer = System.Text.Encoding.Default.GetBytes(str);
char[] delimiter = delim.ToCharArray();string data = "abcd";
Byte[] info = new UTF8Encoding(true).GetBytes(data);这样就可以了啊.....
一个学习ASPNET很不错的群组。强烈推荐大家一起来参加哦!!!
char[] c = new char[str.Length];
for(int i=0;i<str.Length;i++)
{
c[i] = str[i];
}
Response.Write(str+"<br>");
for(int i=0;i<c.Length;i++)
{
Response.Write(c[i]+"<br>");
}