All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在ASP.NET,中实现单点登录_[Asp.Net教程]
在GridView数据源为空时也显示表头_[Asp.Net教程]
PHP学习宝典-第三章 (续篇)_[PHP教程]
对于本专栏,我假设您已经对,Web,部件的基本知识有所了解,例如,如何使用,WebPartMana_[Asp.Net教程]
ASP.NET技巧:教你制做Web实时进度条_[Asp.Net教程]
怎样在vb.net中将图片存入SQL,Server,2000并能读出来使用
delphi无类型文件
了解c#2.0中的Anonymous,Methods(匿名方法)_[Asp.Net教程]
ASP.NET,2.0打造购物车和支付系统之一_[Asp.Net教程]
PHP开发技巧之用递归替换数组中的内容_php资料_编程技术
Reading number is top 10 pictures
清扫五脏垃圾,我有绝招
壮丽的云彩1
The real super beauty15
Terrorist smile the largest human history an explosion1
Ashlynn Brooke show proud chest measurement2
A man's favorite things15
狗狗与主人神同步1
Beautiful Japanese beauty(漂亮的日本美女)3
全身蕾丝丝质美臀
10 powerless things in life
Download software ranking
I for your crazy
Unix video tutorial10
天龙八部最新服务端
VC++6.0培训教程
少妇苏霞全本
I'm come from Beijing2
Unix video tutorial9
双旗镇刀客A
WebService在.NET中的实战应用教学视频 → 第1集
Rio big adventure
delv published in(发表于) 2014/1/24 9:02:59 Edit(编辑)
Asp.net,字符串操作基类(安全,替换,分解等)_[Asp.Net教程]

Asp.net,字符串操作基类(安全,替换,分解等)_[Asp.Net教程]

Asp.net 字符串操作基类(安全,替换,分解等)_[Asp.Net教程]

/############################################
版权声明:
文章内容为本站编辑,创作.你可以任意转载、发布、使用但请务必明文标注文章原始出处及本声明
http://www.opent.cn 作者:浪淘沙
############################################/

/**********************************************************************************
*
* 功能说明:常用函数基类
* 作者: 刘功勋;
* 版本: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
{
///
/// 常用函数基类
///

public class FunObject
{
#region 替换字符串
///
/// 功能:替换字符
///

/// 字符串
/// 替换掉'的字符串
public static string FilterSQL(string strVAlue)
{
string str = "";
str = strVAlue.Replace("''", "");
return str;
}
#endregion

#region 对表 表单内容进行转换HTML操作,
///
/// 功能:对表 表单内容进行转换HTML操作,
///

/// html字符串
///
public static string HtmlCode(string fString)
{
string str = "";
str = fString.Replace(">", ">");
str = fString.Replace("<", "<");
str = fString.Replace(" ", " ");
str = fString.Replace("\n", "
");
str = fString.Replace("\r", "
");
str = fString.Replace("\r\n", "
");

return str;
}
#endregion

#region 判断是否:返回值:√ or ×
///
/// 判断是否:返回值:√ or ×
///

/// true 或false
/// √ or ×
public static string Judgement(bool b)
{
string s = "";
if (b == true)
s = "";
else
s = "×";
return s;
}
#endregion

#region 截取字符串
///
/// 功能:截取字符串长度
///

/// 要截取的字符串
/// 字符串长度
/// true:加...,flase:不加
///
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;
}
else
{
i++;
}
if (i > length)
{
str = str.Substring(0, j);
if (flg)
str += "......";
break;
}
j++;
}
return str;
}
#endregion

#region 截取字符串+…
///
/// 截取字符串+…
///

///
///
///
public static string CutString(string strInput, int intlen)//截取字符串
{
ASCIIEncoding ascii = new ASCIIEncoding();
int intLength = 0;
string strString = "";
byte[] s = ascii.GetBytes(strInput);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
intLength += 2;
}
else
{
intLength += 1;
}

try
{
strString += strInput.Substring(i, 1);
}
catch
{
break;
}

if (intLength > intlen)
{
break;
}
}
//如果截过则加上半个省略号
byte[] mybyte = System.Text.Encoding.Default.GetBytes(strInput);
if (mybyte.Length > intlen)
{
strString += "…";
}
return strString;
}
#endregion

#region 字符串分函数
///
/// 字符串分函数
///

///
///
///
///
public string StringSplit(string strings, int index, string Separ)
{
string[] s = strings.Split(char.Parse(Separ));
return s[index];
}
#endregion

#region 分解字符串为数组
///
/// 字符串分函数
///

/// 要分解的字符串
/// 分割符,可以为string类型
/// 字符数组
public static string[] splitstr(string str, string splitstr)
{
if (splitstr != "")
{
System.Collections.ArrayList c = new System.Collections.ArrayList();
while (true)
{
int thissplitindex = str.IndexOf(splitstr);
if (thissplitindex >= 0)
{
c.Add(str.Substring(0, thissplitindex));
str = str.Substring(thissplitindex + splitstr.Length);
}
else
{
c.Add(str);
break;
}
}
string[] d = new string[c.Count];
for (int i = 0; i < c.Count; i++)
{
d[i] = c[i].ToString();
}
return d;
}
else
{
return new string[] { str };
}
}
#endregion

#region URL编码
///
/// URL编码
///

/// 字符串
///
public static string UrlEncoding(string str)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
return System.Text.Encoding.UTF8.GetString(bytes).ToString();
}
#endregion

#region 获取Web.config中的配置字段值
///
/// 获取全局配置参数
///

/// 键名
/// 参数
public static string GetApp(string key)
{
System.Configuration.AppSettingsReader appr = new System.Configuration.AppSettingsReader();
try
{
string str = (string)appr.GetValue(key, typeof(string));
if (str == null || str == "") return null;
return str;
}
catch (Exception E) { }
return null;
}

#endregion

#region 根据传入的字符串是否为yes/no返回Bit
///
/// 根据传入的字符串是否为yes/no返回Bit
///

///
///
public static int GetBitBool(string flg)
{
int str = 0;
switch (flg.ToLower())
{
case "yes":
str = 1;
break;
case"no":
str = 0;
break;
default:
break;
}
return str;
}
#endregion

#region Html编码
///
/// HTML编码
///

///
///
public static string HtmlEncode(string strInput)
{
string str;
try
{
str = HttpContext.Current.Server.HtmlEncode(strInput);
}
catch
{
str = "error";
}
return str;
}
///
/// HTML解码
///

///
///
public static string HtmlDecode(string strInput)
{
string str;
try
{
str = HttpContext.Current.Server.HtmlDecode(strInput);
}
catch
{
str = "error";
}
return str;
}
#endregion

#region 检测一个字符符,是否在另一个字符中,存在,存在返回true,否则返回false
///
/// 检测一个字符符,是否在另一个字符中,存在,存在返回true,否则返回false
///

/// 原始字符串
/// 目标字符串
///
public static bool IsEnglish(string srcString, string aimString)
{
bool Rev = true;
string chr;
if (aimString == "" || aimString == null) return false;
for (int i = 0; i < aimString.Length; i++)
{
chr = aimString.Substring(i, 1);
if (srcString.IndexOf(chr) < 0)
{
return false;
break;
}

}
return Rev;
}
#endregion

#region 检测字符串中是否含有中文及中文长度
///
/// 检测字符串中是否含有中文及中文长度
///

/// 要检测的字符串
/// 中文字符串长度
public static int CnStringLength(string str)
{
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i = 0; i <= b.Length - 1; i++)
{
if (b[i] == 63) //判断是否为汉字或全脚符号
{
l++;
}
}
return l;

}
#endregion

#region 取字符串右侧的几个字符
///
/// 取字符串右侧的几个字符
///

/// 字符串
/// 右侧的几个字符
///
public static string GetStrRight(string str, int length)
{
string Rev = "";

if (str.Length < length)
{
Rev = str;

}
else
{
Rev = str.Substring(str.Length - length, length);
}
return Rev;


}
#endregion

#region 替换右侧的字符串

///
/// 替换右侧的字符串
///

/// 字符串
/// 右侧的字符串
/// 要替换为的字符串
///
public static string RepStrRight(string str, string strsrc, string straim)
{

string Rev = "";
if (GetStrRight(str, strsrc.Length) != strsrc)
{
Rev = str;
}
else
{
Rev = str.Substring(0, str.Length - strsrc.Length).ToString() + straim.ToString();
}
return Rev;
}
#endregion
}

}

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






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.