c#里的中文字符处理问题(急) 2http://expert.csdn.net/Expert/topic/2872/2872552.xml?temp=.2827112 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 gb18030是先行汉字编码的强制标准。所有用到汉字编码的地方目前都必须符合gb18030 c#中将类序列化为XML文件时,默认的字符编码是UTF-8,但中文也没有任何问题啊。下面是我序列化的代码。////////////////////////////ApplicationSettings是我的类,有string类成员若干,我给它们一些值(中文字符串)//////////////////////////////public bool SaveAppSettings(){ if(this.appSettingsChanged) { StreamWriter myWriter = null; XmlSerializer mySerializer = null; try { // 为 ApplicationSettings 类型 // 创建 XmlSerializer。 mySerializer = new XmlSerializer(typeof(ApplicationSettings)); myWriter = new StreamWriter(@"c:\myApplication.config",false); // 将 ApplicationSettings 类的这一实例 // 序列化到配置文件中。 mySerializer.Serialize(myWriter, this); } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { // 如果 FileStream 是打开的,将其关闭。 if(myWriter != null) { myWriter.Close(); } } } return appSettingsChanged;}序列化后生成的xml文件:<?xml version="1.0" encoding="utf-8"?><ApplicationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <textbox1>大家好</textbox1> <textbox2>我是XXX</textbox2> <textbox3>呵呵</textbox3></ApplicationSettings> 1.encoding="gb2312";2.http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=4723 to: Dugu_Niu(有痔青年)我这样写时,里面有中文就不能正常显示了,为什么呀?其中ourTeam 是一个类的实例,基中包括一些中文信息。private void btnSerial_Click(object sender, System.EventArgs e) { try { XmlSerializer theSerial=new XmlSerializer(typeof(OurTeam)); sw=new StreamWriter("Employee.xml",false); theSerial.Serialize(sw,ourTeam); MessageBox.Show("Yes,everything has been done!"); } catch (Exception excep) { MessageBox.Show(excep.Message); } finally { sw.Flush(); sw.Close(); ourTeam.Clear(); } }运行程序后结果XML文件显示如下:<?xml version="1.0" encoding="utf-8"?><ArrayOfEmployee xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Employee> <Fname>liubin</Fname> <Lname>bill</Lname> <Title>boss</Title> </Employee> <Employee> <Fname>kingcal</Fname> <Lname>chen</Lname> <Title>staff</Title> </Employee> <Employee> <Fname>chen</Fname> <Lname>xiaoquan</Lname> <Title>secretary</Title> </Employee> <Employee> <Fname>鍒?/Fname> <Lname>瀹?/Lname> <Title>澶寸洰</Title> </Employee></ArrayOfEmployee> 第二个问题偶会using System.Text.RegularExpressions;Regex.IsMatch(string1, string2);string1是原始字符串,string2是要匹配的字符,结果是一个bool。 to: mobydick(敌伯威) 要匹配的字符不是具体的呀,比如我要匹配‘ma’与 ‘na’之间的所有字符,包括中文字符该怎么做? 本人菜鸟,问个弱弱的问题 求助~.NET读XML写入SQLSERVER Datatable数据库提交 求救!!!用ADO.NET如何打开DB文件 IDE 问题:始终运行之前的源代码 有没有类似QQ样式的控件? VB6调用一com组件的问题,请高手帮忙 一个简单的winForm问题,在主窗体树形菜单部分,是放在另外一个窗体中的,通过new这个窗体在主窗体中显示,问题是.............. process的用法大讨论 Vs2012中XAML关键字颜色的问题... 问一个datagrid的问题~~急 请教高手
但中文也没有任何问题啊。
下面是我序列化的代码。//////////////////////////
//ApplicationSettings是我的类,有string类成员若干,我给它们一些值(中文字符串)
//
////////////////////////////public bool SaveAppSettings()
{
if(this.appSettingsChanged)
{
StreamWriter myWriter = null;
XmlSerializer mySerializer = null;
try
{
// 为 ApplicationSettings 类型
// 创建 XmlSerializer。
mySerializer = new XmlSerializer(typeof(ApplicationSettings));
myWriter = new StreamWriter(@"c:\myApplication.config",false);
// 将 ApplicationSettings 类的这一实例
// 序列化到配置文件中。
mySerializer.Serialize(myWriter, this);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// 如果 FileStream 是打开的,将其关闭。
if(myWriter != null)
{
myWriter.Close();
}
}
}
return appSettingsChanged;
}序列化后生成的xml文件:<?xml version="1.0" encoding="utf-8"?>
<ApplicationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<textbox1>大家好</textbox1>
<textbox2>我是XXX</textbox2>
<textbox3>呵呵</textbox3>
</ApplicationSettings>
2.http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=4723
其中ourTeam 是一个类的实例,基中包括一些中文信息。
private void btnSerial_Click(object sender, System.EventArgs e)
{
try
{
XmlSerializer theSerial=new XmlSerializer(typeof(OurTeam));
sw=new StreamWriter("Employee.xml",false);
theSerial.Serialize(sw,ourTeam);
MessageBox.Show("Yes,everything has been done!");
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
finally
{
sw.Flush();
sw.Close();
ourTeam.Clear();
}
}
运行程序后结果XML文件显示如下:<?xml version="1.0" encoding="utf-8"?>
<ArrayOfEmployee xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<Fname>liubin</Fname>
<Lname>bill</Lname>
<Title>boss</Title>
</Employee>
<Employee>
<Fname>kingcal</Fname>
<Lname>chen</Lname>
<Title>staff</Title>
</Employee>
<Employee>
<Fname>chen</Fname>
<Lname>xiaoquan</Lname>
<Title>secretary</Title>
</Employee>
<Employee>
<Fname>鍒?/Fname>
<Lname>瀹?/Lname>
<Title>澶寸洰</Title>
</Employee>
</ArrayOfEmployee>
string1是原始字符串,string2是要匹配的字符,结果是一个bool。
要匹配的字符不是具体的呀,比如我要匹配‘ma’与 ‘na’之间的所有字符,包括中文字符
该怎么做?