public static String urlCharactersEncoding(String str) { if (QSStringUtil.isEmpty(str)) { return(""); } StringBuilder buffer = new StringBuilder(); try { for (int i = 0; i < str.Length; i++) { String temp = str.Substring(i, 1); if (' '.Equals(temp)) { buffer.Append("%20"); } else if ('/'.Equals(temp) || '&'.Equals(temp) || '='.Equals(temp) || ':'.Equals(temp)) { buffer.Append(temp); } else { buffer.Append(HttpUtility.UrlEncode(temp, Encoding.GetEncoding(QSConstant.ENCODING_UTF8))); } } return(buffer.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } return(""); }
/** * Chinese characters transform * * @param str * @return */ public static string chineseCharactersEncoding(string str) { if (QSStringUtil.isEmpty(str)) { return(""); } StringBuilder buffer = new StringBuilder(); try { for (int i = 0; i < str.Length; i++) { string temp = str.Substring(i, 1); if (Encoding.UTF8.GetBytes(temp).Length > 1) { buffer.Append(HttpUtility.UrlEncode(temp, Encoding.GetEncoding(QSConstant.ENCODING_UTF8))); } else { buffer.Append(temp); } } return(buffer.ToString()); } catch (Exception e) { System.Console.WriteLine(e.Message); } return(null); }