ÿþusing System; using System.Collections.Generic; using System.Collections; using System.Text; using System.Web; using System.IO; namespace HH.WMS.Utils { public partial class ZString { ///// <summary> ///// lbc:N€{SO-N‡e using Microsoft.VisualBasic; ///// </summary> //public static string ToSChinese(string str) //{ // return Strings.StrConv(str, VbStrConv.SimplifiedChinese, 0); //} ///// <summary> ///// lbc:NA~SO-N‡e ///// </summary> //public static string ToTChinese(string str) //{ // return Strings.StrConv(str, VbStrConv.TraditionalChinese, 0); //} /// <summary> /// ԏÞV HTML W[&{2N„vxÓ~œg /// </summary> /// <param name="str">W[&{2N</param> /// <returns>xÓ~œg</returns> public static string HtmlEncode(string str) { return HttpUtility.HtmlEncode(str); } /// <summary> /// ԏÞV HTML W[&{2N„vã‰xÓ~œg /// </summary> /// <param name="str">W[&{2N</param> /// <returns>ã‰xÓ~œg</returns> public static string HtmlDecode(string str) { return HttpUtility.HtmlDecode(str); } /// <summary> /// ԏÞV URL W[&{2N„vxÓ~œg /// </summary> /// <param name="str">W[&{2N</param> /// <returns>xÓ~œg</returns> public static string UrlEncode(string str) { return HttpUtility.UrlEncode(str); } /// <summary> /// ԏÞV URL W[&{2N„vxÓ~œg /// </summary> /// <param name="str">W[&{2N</param> /// <returns>ã‰xÓ~œg</returns> public static string UrlDecode(string str) { return HttpUtility.UrlDecode(str); } /// <summary> /// ԏÞVcš[îvU_ N„v^— UTF8 W[&{Ɩ‡eöN /// </summary> /// <param name="Path">_</param> /// <returns>‡eöN T„vW[&{2NpeÄ~</returns> public static string[] FindNoUTF8File(string Path) { List<string> filelist = new List<string>(); DirectoryInfo Folder = new DirectoryInfo(Path); FileInfo[] subFiles = Folder.GetFiles(); for (int j = 0; j < subFiles.Length; j++) { if (subFiles[j].Extension.ToLower().Equals(".htm")) { FileStream fs = new FileStream(subFiles[j].FullName, FileMode.Open, FileAccess.Read); bool bUtf8 = IsUTF8(fs); fs.Close(); if (!bUtf8) { filelist.Add(subFiles[j].FullName); } } } return filelist.ToArray(); } //0000 0000-0000 007F - 0xxxxxxx (ascii converts to 1 octet!) //0000 0080-0000 07FF - 110xxxxx 10xxxxxx ( 2 octet format) //0000 0800-0000 FFFF - 1110xxxx 10xxxxxx 10xxxxxx (3 octet format) /// <summary> /// $R­e‡eöNAm/f&T:NUTF8W[&{Ɩ /// </summary> /// <param name="sbInputStream">‡eöNAm</param> /// <returns>$R­eÓ~œg</returns> private static bool IsUTF8(FileStream sbInputStream) { int i; byte cOctets; // octets to go in this UTF-8 encoded character byte chr; bool bAllAscii = true; long iLen = sbInputStream.Length; cOctets = 0; for (i = 0; i < iLen; i++) { chr = (byte)sbInputStream.ReadByte(); if ((chr & 0x80) != 0) bAllAscii = false; if (cOctets == 0) { if (chr >= 0x80) { do { chr <<= 1; cOctets++; } while ((chr & 0x80) != 0); cOctets--; if (cOctets == 0) return false; } } else { if ((chr & 0xC0) != 0x80) { return false; } cOctets--; } } if (cOctets > 0) { return false; } if (bAllAscii) { return false; } return true; } /// <summary> /// \hQ҉peW[lbc:NpeW[ /// </summary> /// <param name="SBCCase"></param> /// <returns></returns> public static string SBCCaseToNumberic(string SBCCase) { char[] c = SBCCase.ToCharArray(); for (int i = 0; i < c.Length; i++) { byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1); if (b.Length == 2) { if (b[1] == 255) { b[0] = (byte)(b[0] + 32); b[1] = 0; c[i] = System.Text.Encoding.Unicode.GetChars(b)[0]; } } } return new string(c); } } }