You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.2 KiB
150 lines
4.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Stone.Common
|
|
{
|
|
public class MyStrings
|
|
{
|
|
/// <summary>
|
|
/// 取得MD5加密字串
|
|
/// </summary>
|
|
/// <param name="Message">要加密的字串</param>
|
|
/// <returns></returns>
|
|
public static string GetMD5String(string Message)
|
|
{
|
|
return Biz.MD5.MDString(Message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得MD5文件加密字串
|
|
/// </summary>
|
|
/// <param name="FileName">要加密的文件路径</param>
|
|
/// <returns></returns>
|
|
public static string GetMD5File(string FileName)
|
|
{
|
|
return Biz.MD5.MDFile(FileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 简单加密一个字串
|
|
/// </summary>
|
|
/// <param name="rs">要加密的字串</param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 简单解密一个字串
|
|
/// </summary>
|
|
/// <param name="rs">要解密的字串</param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在指定字串右边填充指定的字串
|
|
/// </summary>
|
|
/// <param name="o_str">要填充的原字串</param>
|
|
/// <param name="p_str">填充的字符</param>
|
|
/// <param name="len">要填充的长度</param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得SQL参数字串(替换直接SQL参数中的单引号)
|
|
/// </summary>
|
|
/// <param name="str">要替换的SQL参数</param>
|
|
/// <returns>替换后的SQL参数</returns>
|
|
public static string GetString(string str)
|
|
{
|
|
string reslut = "";
|
|
reslut = str.Replace("'", "''");
|
|
return reslut;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 格式化金额显示
|
|
/// </summary>
|
|
/// <param name="d"></param>
|
|
/// <returns></returns>
|
|
public static string FormatPrice(Decimal d)
|
|
{
|
|
string ret = Math.Round(d, 2) + "";
|
|
return ret;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 分割字符串
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <param name="pattern"></param>
|
|
/// <returns></returns>
|
|
public static string[] split(string str, string pattern)
|
|
{
|
|
return Regex.Split(str, pattern, RegexOptions.IgnoreCase);
|
|
}
|
|
}
|
|
}
|
|
|