using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace Stone.Common { public class MyStrings { /// /// 取得MD5加密字串 /// /// 要加密的字串 /// public static string GetMD5String(string Message) { return Biz.MD5.MDString(Message); } /// /// 取得MD5文件加密字串 /// /// 要加密的文件路径 /// public static string GetMD5File(string FileName) { return Biz.MD5.MDFile(FileName); } /// /// 简单加密一个字串 /// /// 要加密的字串 /// public static string DecryptStr(string rs) { //byte[] by = new byte[rs.Length]; //for (int i = 0; //i <= rs.Length - 1; //i++) //{ // by[i] = (byte)((byte)rs[i] - 1); //} //rs = ""; //for (int i = by.Length - 1; //i >= 0; //i--) //{ // rs += ((char)by[i]).ToString(); //} //return rs; return DEncrypt.Decrypt(rs); } /// /// 简单解密一个字串 /// /// 要解密的字串 /// public static string EncryptStr(string rs) //倒序加1加密 { //byte[] by = new byte[rs.Length]; //for (int i = 0; //i <= rs.Length - 1; //i++) //{ // by[i] = (byte)((byte)rs[i] + 1); //} //rs = ""; //for (int i = by.Length - 1; //i >= 0; //i--) //{ // rs += ((char)by[i]).ToString(); //} //return rs; return DEncrypt.Encrypt(rs); } /// /// 在指定字串右边填充指定的字串 /// /// 要填充的原字串 /// 填充的字符 /// 要填充的长度 /// public static string PadLeftString(string o_str, char p_str, int len) { string result; if (o_str.Length > len) { result = o_str.Substring(0, len); } else { int slen = len - o_str.Length; result = o_str; while (slen > 0) { result = p_str.ToString() + result; slen--; } } return result; } public static int GetLength(string str) { return System.Text.Encoding.Default.GetBytes(str).Length; } /// /// 取得SQL参数字串(替换直接SQL参数中的单引号) /// /// 要替换的SQL参数 /// 替换后的SQL参数 public static string GetString(string str) { string reslut = ""; reslut = str.Replace("'", "''"); return reslut; } /// /// 格式化金额显示 /// /// /// public static string FormatPrice(Decimal d) { string ret = Math.Round(d, 2) + ""; return ret; } /// /// 分割字符串 /// /// /// /// public static string[] split(string str, string pattern) { return Regex.Split(str, pattern, RegexOptions.IgnoreCase); } } }