网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

asp.net怎么解决文本中文乱码的问题

本篇内容介绍了“asp.net怎么解决文本中文乱码的问题”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联建站服务项目包括靖州网站建设、靖州网站制作、靖州网页制作以及靖州网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,靖州网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到靖州省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

 /// 
        /// 解决文本中文乱码   各类文本编码转UTF-8 文本
        /// 
        /// 原路径
        /// 临时保存路径
        /// 新的文件路径
        /// 新文件路径
        public static string  GetUtf8(string fullPath,string savePath,string strnew)
        {
                             Encoding e =GetFileEncodeType(fullPath);
                                System.IO.File.Create(savePath).Close();
                     using (StreamReader sr = new StreamReader(fullPath, e, false))
                                {
                              string utf8info = string.Empty;
                            Encoding utf8 = Encoding.UTF8;
                             // Convert the string into a byte[]. 
                           byte[] unicodeBytes = e.GetBytes(sr.ReadToEnd());
                           // Perform. the conversion from one encoding to the other. 
                           byte[] asciiBytes = Encoding.Convert(e, utf8, unicodeBytes);
                         // Convert the new byte[] into a char[] and then into a string. 
                        // This is a slightly different approach to converting tillustrate 
                      // the use of GetCharCount/GetChars. 
        char[] asciiChars = new char[utf8.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
         utf8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
         utf8info = new string(asciiChars);
         using (StreamWriter sw = new StreamWriter(savePath, false, Encoding.UTF8))
                                    {
                                        sw.Write(utf8info);
                                    }
                                }
                                System.IO.File.Delete(fullPath);
                                System.IO.File.Copy(savePath,strnew,true);
                                System.IO.File.Delete(savePath);
                                return strnew;
        }
方法2
                    using (FileStream fs = new FileStream(fullPath, FileMode.Open))
                                {
                           using (StreamReader sr = new StreamReader(fs,Encoding.Default))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            string sLine = sr.ReadLine();
                                            //StringBuilder b = new StringBuilder();
                                            //b.AppendLine(sLine);
                                            //另存到其他txt文件中   
                using (StreamWritersw=System.IO.File.AppendText(savepath))
                                            {
                                                //string n = b.ToString();
                                                sw.WriteLine(sLine.ToString());
                                            }
                                        }
                                    }
                                }
                                System.IO.File.Delete(fullPath);
                                string strNewFile = fullPath;
                                System.IO.File.Copy(savepath, strNewFile, true);
                                System.IO.File.Delete(savepath);
           //using (StreamReader sr = new StreamReader(strNewFile,Encoding.Default, false))
                                //{
              //    using (StreamWriter sw = new StreamWriter(fullPath, falsEncoding.UTF8))
                                //    {
                                //        sw.Write(Server.HtmlEncode(sr.ReadToEnd()));
                                //    }
                                //}
                                //System.IO.File.Delete(strNewFile);
                                FileInfo fileNew = new FileInfo(strNewFile);
                                sourcesFile.File_Size = fileNew.Length;
                                this.sourcesFileService.Save(sourcesFile);
                            }

“asp.net怎么解决文本中文乱码的问题”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


文章题目:asp.net怎么解决文本中文乱码的问题
文章路径:http://bjjierui.cn/article/jphihp.html

其他资讯