怎样使页面编码从GB2312转成UTF-8?

pcbaby 2005-06-08 10:40:14
因为不同组件之间的编码方式不同,使用同一个会显示乱码,现在我的缺省是GB2312的,但是有一页需要使用UTF-8编码,怎么办?急
...全文
279 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
brando_beat 2005-06-08
  • 打赏
  • 举报
回复
up
pcbaby 2005-06-08
  • 打赏
  • 举报
回复
用flyye_cs(一叶孤舟) 的代码,执行这里时提示路径中含有非法字符,我那段需要UTF-8编码的是上传代码file.SaveAs(Path.Combine(path, Path.GetFileName(file.FileName)));

FileName这里出错,转成UTF-8的又不认了,但是用GB2312的是乱码,web.config页面里的是UTF-8的显示正常
sunnystar365 2005-06-08
  • 打赏
  • 举报
回复
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
flyye_cs 2005-06-08
  • 打赏
  • 举报
回复
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)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", unicodeString);
Console.WriteLine("Ascii converted string: {0}", asciiString);
}
}
}
czsxj 2005-06-08
  • 打赏
  • 举报
回复
Response.Charset="utf-8";
pcbaby 2005-06-08
  • 打赏
  • 举报
回复
我要用代码改啊,web.config里面就得用GB2312,只有一页用了一个组件的,那个组件只支持UTF-8编码
luckyprg 2005-06-08
  • 打赏
  • 举报
回复
可以改页面中的charset=utf-8,
也可以改web.config,
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
lovefootball 2005-06-08
  • 打赏
  • 举报
回复
在aspx里
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
fengfangfang 2005-06-08
  • 打赏
  • 举报
回复
设置Response.Charset
老戴12345654 2005-06-08
  • 打赏
  • 举报
回复
用这个试一下
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧