首页 > 编程 > .NET > 正文

Asp.net 字符串操作基类(安全,替换,分解等)

2024-07-10 12:39:34
字体:
来源:转载
供稿:网友
/**********************************************************************************
*
* 功能说明:常用函数基类
* 作者: 刘功勋;
* 版本:V0.1(C#2.0);时间:2006-8-13
*
* *******************************************************************************/
/***************************************************************
* 更新记录
* 2007-1-5 更新:
* 1,取字符串右侧的几个字符
* 2,替换右侧的字符串
****************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
namespace EC
{
/// <summary>
/// 常用函数基类
/// </summary>
public class FunObject
{
#region 替换字符串
/// <summary>
/// 功能:替换字符
/// </summary>
/// <param name="strVAlue">字符串</param>
/// <returns>替换掉'的字符串</returns>
public static string FilterSQL(string strVAlue)
{
string str = "";
str = strVAlue.Replace("''", "");
return str;
}
#endregion
#region 对表 表单内容进行转换HTML操作,
/// <summary>
/// 功能:对表 表单内容进行转换HTML操作,
/// </summary>
/// <param name="fString">html字符串</param>
/// <returns></returns>
public static string HtmlCode(string fString)
{
string str = "";
str = fString.Replace(">", ">");
str = fString.Replace("<", "<");
str = fString.Replace(" ", " ");
str = fString.Replace("/n", "<br />");
str = fString.Replace("/r", "<br />");
str = fString.Replace("/r/n", "<br />");
return str;
}
#endregion
#region 判断是否:返回值:√ or ×
/// <summary>
/// 判断是否:返回值:√ or ×
/// </summary>
/// <param name="b">true 或false</param>
/// <returns>√ or ×</returns>
public static string Judgement(bool b)
{
string s = "";
if (b == true)
s = "<b><font color=#009900>√</font></b>";
else
s = "<b><font color=#FF0000>×</font></b>";
return s;
}
#endregion
#region 截取字符串
/// <summary>
/// 功能:截取字符串长度
/// </summary>
/// <param name="str">要截取的字符串</param>
/// <param name="length">字符串长度</param>
/// <param name="flg">true:加...,flase:不加</param>
/// <returns></returns>
public static string GetString(string str, int length, bool flg)
{
int i = 0, j = 0;
foreach (char chr in str)
{
if ((int)chr > 127)
{
i += 2;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表