In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to solve the problem of Chinese garbled code in asp.net". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
/ solve Chinese text garbled all kinds of text coding to UTF-8 text / original path / temporary save path / new file path / new file path 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 } method 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) / / Save to another txt file 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);} "how to solve the problem of garbled code in Chinese text by asp.net" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.