asp.net中常用的字符串处理类

 代码如下 复制代码

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("rn", "
");

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
}

}

实例二

一些常用字符串操作的代码!大家直接看代码!!

 

 代码如下 复制代码

using System;

namespace Web.StringUtil
{
    /// <summary>
    /// 字符串操作工具集
    /// </summary>
    public class StringUtil
    {                   
        public StringUtil()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //           
        }

        /// <summary>
        /// 从字符串中的尾部删除指定的字符串
        /// </summary>
        /// <param name="sourceString"></param>
        /// <param name="removedString"></param>
        /// <returns></returns>
        public static string Remove(string sourceString,string removedString)
        {
            try
            {
                if( sourceString.IndexOf(removedString) < 0 )
                {   
                    throw new Exception("原字符串中不包含移除字符串!");
                }
                string result = sourceString;
                int lengthOfSourceString = sourceString.Length;
                int lengthOfRemovedString = removedString.Length;
                int startIndex = lengthOfSourceString - lengthOfRemovedString;
                string tempSubString = sourceString.Substring(startIndex);
                if(tempSubString.ToUpper() == removedString.ToUpper())
                {                   
                    result = sourceString.Remove(startIndex,lengthOfRemovedString);
                }
                return result;
            }
            catch
            {
                return sourceString;
            }
        }

        /// <summary>
        /// 获取拆分符右边的字符串
        /// </summary>
        /// <param name="sourceString"></param>
        /// <param name="splitChar"></param>
        /// <returns></returns>
        public static string RightSplit(string sourceString, char splitChar)
        {
            string result=null;
            string[] tempString = sourceString.Split(splitChar);
            if(tempString.Length >0)
            {
                result = tempString[tempString.Length-1].ToString();
            }
            return result;
        }
       
        /// <summary>
        /// 获取拆分符左边的字符串
        /// </summary>
        /// <param name="sourceString"></param>
        /// <param name="splitChar"></param>
        /// <returns></returns>
        public static string LeftSplit(string sourceString, char splitChar)
        {
            string result=null;
            string[] tempString = sourceString.Split(splitChar);
            if(tempString.Length >0)
            {
                result = tempString[0].ToString();
            }
            return result;
        }

        /// <summary>
        /// 去掉最后一个逗号
        /// </summary>
        /// <param name="origin"></param>
        /// <returns></returns>
        public static string DelLastComma(string origin)
        {
            if(origin.IndexOf(",") == -1)
            {
                return origin;
            }
            return origin.Substring(0,origin.LastIndexOf(","));
        }

        /// <summary>
        /// 删除不可见字符
        /// </summary>
        /// <param name="sourceString"></param>
        /// <returns></returns>
        public static string DeleteUnVisibleChar(string sourceString)
        {
            System.Text.StringBuilder sBuilder = new System.Text.StringBuilder(131);
            for(int i = 0;i < sourceString.Length; i++)
            {
                int Unicode = sourceString[i];
                if(Unicode >= 16)
                {
                    sBuilder.Append(sourceString[i].ToString());
                }               
            }
            return sBuilder.ToString();
        }

        /// <summary>
        /// 获取数组元素的合并字符串
        /// </summary>
        /// <param name="stringArray"></param>
        /// <returns></returns>
        public static string GetArrayString(string[] stringArray)
        {
            string totalString = null;
            for(int i=0;i<stringArray.Length;i++)
            {
                totalString = totalString + stringArray[i];               
            }
            return totalString;
        }

        /// <summary>
        ///        获取某一字符串在字符串数组中出现的次数
        /// </summary>
        /// <param name="stringArray" type="string[]">
        ///     <para>
        ///        
        ///     </para>
        /// </param>
        /// <param name="findString" type="string">
        ///     <para>
        ///        
        ///     </para>
        /// </param>
        /// <returns>
        ///     A int value
        /// </returns>
        public static int GetStringCount(string[] stringArray,string findString)
        {
            int count = -1;                       
            string totalString = GetArrayString(stringArray);       
            string subString = totalString;

            while(subString.IndexOf(findString)>=0)
            {
                subString = totalString.Substring(subString.IndexOf(findString));
                count += 1;
            }
            return count;
        }

        /// <summary>
        ///     获取某一字符串在字符串中出现的次数
        /// </summary>
        /// <param name="stringArray" type="string">
        ///     <para>
        ///         原字符串
        ///     </para>
        /// </param>
        /// <param name="findString" type="string">
        ///     <para>
        ///         匹配字符串
        ///     </para>
        /// </param>
        /// <returns>
        ///     匹配字符串数量
        /// </returns>
        public static int GetStringCount(string sourceString,string findString)
        {
            int count = 0;   
            int findStringLength = findString.Length;
            string subString = sourceString;

            while(subString.IndexOf(findString)>=0)
            {
                subString = subString.Substring(subString.IndexOf(findString)+findStringLength);
                count += 1;
            }
            return count;
        }

        /// <summary>
        /// 截取从startString开始到原字符串结尾的所有字符  
        /// </summary>
        /// <param name="sourceString" type="string">
        ///     <para>
        ///        
        ///     </para>
        /// </param>
        /// <param name="startString" type="string">
        ///     <para>
        ///        
        ///     </para>
        /// </param>
        /// <returns>
        ///     A string value
        /// </returns>
        public static string GetSubString(string sourceString,string startString)
        {
            try
            {
                int index = sourceString.ToUpper().IndexOf(startString);
                if(index>0)
                {
                    return sourceString.Substring(index);
                }
                return sourceString;
            }
            catch
            {
                return "";
            }
        }

        public static string GetSubString(string sourceString,string beginRemovedString,string endRemovedString)
        {
            try
            {
                if(sourceString.IndexOf(beginRemovedString)!=0)
                {   
                    beginRemovedString = "";
                }

                if(sourceString.LastIndexOf(endRemovedString,sourceString.Length - endRemovedString.Length)<0)
                {
                    endRemovedString = "";
                }
                int startIndex = beginRemovedString.Length;
                int length     = sourceString.Length - beginRemovedString.Length - endRemovedString.Length ;
                if(length>0)
                {
                    return sourceString.Substring(startIndex,length);
                }
                return sourceString;
            }
            catch
            {
                return sourceString;;
            }
        }
       
        /// <summary>
        /// 按字节数取出字符串的长度
        /// </summary>
        /// <param name="strTmp">要计算的字符串</param>
        /// <returns>字符串的字节数</returns>
        public static int GetByteCount(string strTmp)
        {
            int intCharCount=0;
            for(int i=0;i<strTmp.Length;i++)
            {
                if(System.Text.UTF8Encoding.UTF8.GetByteCount(strTmp.Substring(i,1))==3)
                {
                    intCharCount=intCharCount+2;
                }
                else
                {
                    intCharCount=intCharCount+1;
                }
            }
            return intCharCount;
        }

        /// <summary>
        /// 按字节数要在字符串的位置
        /// </summary>
        /// <param name="intIns">字符串的位置</param>
        /// <param name="strTmp">要计算的字符串</param>
        /// <returns>字节的位置</returns>
        public static int GetByteIndex(int intIns,string strTmp)
        {
            int intReIns=0;
            if(strTmp.Trim()=="")
            {
                return intIns;
            }
            for(int i=0;i<strTmp.Length;i++)
            {
                if(System.Text.UTF8Encoding.UTF8.GetByteCount(strTmp.Substring(i,1))==3)
                {
                    intReIns=intReIns+2;
                }
                else
                {
                    intReIns=intReIns+1;
                }
                if(intReIns>=intIns)
                {
                    intReIns=i+1;
                    break;
                }           
            }
            return intReIns;
        }
    }
}

实例三

 代码如下 复制代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.IO;
using System.Text;

namespace StringClass
{
    public class StringHelper
    {
        /// <summary>
        /// 去掉字符串中的所有空格
        /// </summary>
        /// <param name="_str"></param>
        /// <returns></returns>
        public static string ReMoveBlank(string _str)
        {
            string strTemp = "";
            CharEnumerator CEnumerator = _str.GetEnumerator();
            while (CEnumerator.MoveNext())
            {
                byte[] array = new byte[1];
                array = System.Text.Encoding.ASCII.GetBytes(CEnumerator.Current.ToString());
                int asciicode = (short)(array[0]);
                if (asciicode != 32)
                {
                    strTemp += CEnumerator.Current.ToString();
                }
            }
            return strTemp;
        }

        /// <summary>
        /// 截取字符串并限制字符串长度,多于给定的长度+。。。
        /// </summary>
        /// <param name="str">待截取的字符串</param>
        /// <param name="len">每行的长度,多于这个长度自动换行</param>
        /// <param name="max">输出字符串最大的长度</param>
        /// <returns></returns>
        public static string CutStr(string str, int len, int max)
        {
            string s = "";
            string sheng = "";
            if (str.Length > max)
            {
                str = str.Substring(0, max);
                sheng = "";
            }
            for (int i = 0; i < str.Length; i++)
            {
                int r = i % len;
                int last = (str.Length / len) * len;
                if (i != 0 && i <= last)
                {
                    if (r == 0)
                    {
                        s += str.Substring(i - len, len) + "<br>";
                    }

                }
                else if (i > last)
                {
                    s += str.Substring(i - 1);
                    break;
                }

            }
            return s + sheng;
        }

        /// <summary>
        /// 截取字符串,不限制字符串长度
        /// </summary>
        /// <param name="str">待截取的字符串</param>
        /// <param name="len">每行的长度,多于这个长度自动换行</param>
        /// <returns></returns>
        public static string CutStr(string str, int len)
        {
            string s = "";
            for (int i = 0; i < str.Length; i++)
            {
                int r = i % len;
                int last = (str.Length / len) * len;
                if (i != 0 && i <= last)
                {
                    if (r == 0)
                    {
                        s += str.Substring(i - len, len) + "<br>";
                    }
                }
                else if (i > last)
                {
                    s += str.Substring(i - 1);
                    break;
                }
            }
            return s;
        }

        public static string PartSubString(string str, int len)
        {
            if (str.Length > len)
            {
                return str.Substring(0, len) + "...";
            }
            return str;
        }

        /// <summary>
        ///这个方法确保用户的输入不是恶毒的
        /// </summary>
        /// <param name="text">输入字符串</param>
        /// <param name="maxLength">最大长度</param>
        /// <returns>转换后的字符串</returns>
        public static string InputText(string text, int maxLength)
        {
            text = text.Trim();
            if (string.IsNullOrEmpty(text))
                return string.Empty;
            if (text.Length > maxLength)
                text = text.Substring(0, maxLength);
            text = Regex.Replace(text, "[\s]{2,}", " "); //two or more spaces
            text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\n)*?>)", "n"); //<br>
            text = Regex.Replace(text, "(\s*&[n|N][b|B][s|S][p|P];\s*)+", " "); //&nbsp;
            text = Regex.Replace(text, "<(.|\n)*?>", string.Empty); //any other tags
            text = text.Replace("'", "''");
            return text;
        }

        /// <summary>
        /// 字符串中大写字符转小写
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string StringToLower(string str)
        {
            Char[] a = str.ToCharArray();
            string strTemp = "";
            for (int i = 0; i < a.Length; i++)
            {
                if (Convert.ToInt32(a[i]) >= 65 && Convert.ToInt32(a[i]) <= 90)
                    strTemp += a[i].ToString().ToLower();
                else
                    strTemp += a[i].ToString();
            }
            return strTemp;
        }

        /// <summary>  
        /// 加密  
        /// </summary>  
        /// <param name="str"></param>  
        /// <param name="key">必须是8位的字符串</param>  
        /// <returns></returns>  
        public static string Encode(string str, int keyIndex)
        {
            ArrayList alKey = new ArrayList();
            alKey.Add("BookT@#+!NumBq2");
            alKey.Add("MagaZine@(21&*ID5");
            alKey.Add("ThesisDSHI}._Y");
            string key = alKey[keyIndex].ToString();
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(str);
            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
            stream2.Write(bytes, 0, bytes.Length);
            stream2.FlushFinalBlock();
            StringBuilder builder = new StringBuilder();
            foreach (byte num in stream.ToArray())
            {
                builder.AppendFormat("{0:X2}", num);
            }
            stream.Close();
            return builder.ToString();
        }

        /// <summary>  
        /// Des 解密 GB2312   
        /// </summary>  
        /// <param name="str">Desc string</param>  
        /// <param name="key">Key ,必须为8位 </param>  
        /// <returns></returns>  
        public static string Decode(string str, int keyIndex)
        {
            ArrayList alKey = new ArrayList();
            alKey.Add("BookT@#+!NumBq2");
            alKey.Add("MagaZine@(21&*ID5");
            alKey.Add("ThesisDSHI}._Y");
            string key = alKey[keyIndex].ToString();
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            byte[] buffer = new byte[str.Length / 2];
            for (int i = 0; i < (str.Length / 2); i++)
            {
                int num2 = Convert.ToInt32(str.Substring(i * 2, 2), 0x10);
                buffer[i] = (byte)num2;
            }
            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
            stream2.Write(buffer, 0, buffer.Length);
            stream2.FlushFinalBlock();
            stream.Close();
            return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
        }

        /// <summary>
        /// MD5不可逆加密 32位
        /// </summary>
        /// <param name="s"></param>
        /// <param name="_input_charset"></param>
        /// <returns></returns>
        public static string GetMD5_32(string str1)
        {
            string cl1 = str1;
            string pwd = "";
            MD5 md5 = MD5.Create();
            // 加密后是一个字节类型的数组
            byte[] s = md5.ComputeHash(Encoding.Unicode.GetBytes(cl1));
            // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
            for (int i = 0; i < s.Length; i++)
            {
                // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
                pwd = pwd + s[i].ToString("x");
            }
            return pwd;
        }
        /// <summary>
        /// MD5不可逆加密 16位
        /// </summary>
        /// <param name="ConvertString"></param>
        /// <returns></returns>
        public static string GetMd5_16(string ConvertString)
        {

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);

            t2 = t2.Replace("-", "");

            return t2;

        }
    }
}

时间: 2024-09-20 12:31:44

asp.net中常用的字符串处理类的相关文章

ASP.NET中常用输出JS脚本的类实例_实用技巧

本文实例讲述了ASP.NET中常用输出JS脚本的类,针对过去输出js脚本的类进行了一定的改进.在项目开发中非常具有实用价值.分享给大家供大家参考.具体如下: 很多时候在ASP.NET中我们经常需要输出一些JS脚本,比如弹出一个警告窗口,返回到历史页面等JS功能,我看到网上流传得比较广的是马先光写的一个JScript类,这个类基本将经常用到的JS脚本包含了,非常方便,唯一的不足是作者采用的Response.Write(string msg)的办法,这样造成输出的js脚本在<html></h

ASP.NET中常用的文件上传下载方法

asp.net|上传|下载     文件的上传下载是我们在实际项目开发过程中经常需要用到的技术,这里给出几种常见的方法,本文主要内容包括:1.如何解决文件上传大小的限制2.以文件形式保存到服务器3.转换成二进制字节流保存到数据库以及下载方法4.上传Internet上的资源 第一部分:    首先我们来说一下如何解决ASP.NET中的文件上传大小限制的问题,我们知道在默认情况下ASP.NET的文件上传大小限制为2M,一般情况下,我们可以采用更改WEB.Config文件来自定义最大文件大小,如下:<

asp.net中常用到的SQL分页存储过程

asp.net中常用到的SQL分页存储过程 以下是引用片段:create PROCEDURE [dbo].[myPage] @tblName varchar(255), -- 表名 @fldName varchar(255), -- 排序的字段名,一般为唯一标识 @strGetFields varchar(1000) = ' * ', -- 需要返回的列  @PageSize int = 10, -- 每页有多少条记录 @PageIndex int = 1, -- 第几页 @Count int 

在asp/asp.net中调用java写的类

asp.net|asp.net 在开发过程中偶尔会遇到要在ASP/ASP.Net中调用JAVA写的类,以实现之前已经用JAVA实现的功能,下面就以一个简单示例说明详细的使用方法: 1.创建java文件:使用任何你喜欢的编辑器编辑以下内容:public class hello{ public String helloWorld(String s) { if(s == null) return ""; else return s; }}将此文件保存为hello.java 2.编译java文

Asp.NET中常用的一些优化性能的方法

asp.net|性能|优化 Asp.NET中常用的一些优化性能的方法 ASP.NET 的缓存机制相比ASP有很大的改进,本文档除对常用优化方法进行总结介绍外,强调了如何使用ASP.NET的缓存来获得最佳性能. 1:不要使用不必要的session和ASP中一样,在不必要的时候不要使用Session. 可以针对整个应用程序或者页面禁用会话状态: l 禁用页面的会话状态 l 禁用应用程序的会话状态 在应用程序的Web.Config文件的sessionstate配置节中,将mode属性设置为off. 即

浅谈Java中常用数据结构的实现类 Collection和Map_java

线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以及如何正确使用这些类. Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtable ├HashMap └WeakHashMap Collection接口 Collection是最基本的集合接口,一个C

必知技巧:ASP.NET中常用的优化性能方法详解

asp.net|技巧|详解|性能|优化 1. 数据库访问性能优化 数据库的连接和关闭 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源.ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响.系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求. 连接池的大小是有限的,如果在连接池达到最大限度后仍要求创建连接,必然大大影响性能.因此,在建立数据库连接后

ASP.NET中常用的优化性能方法

asp.net|性能|优化 1. 数据库访问性能优化 数据库的连接和关闭 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源.ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响.系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求. 连接池的大小是有限的,如果在连接池达到最大限度后仍要求创建连接,必然大大影响性能.因此,在建立数据库连接后只有在真正需

asp开发中常用函数

asp教程开发中常用函数 sub lastnextpage(pagecount,page,table_style,font_style) '生成上一页下一页链接  dim query, a, x, temp  action = "http://" & request.servervariables("http_host") & request.servervariables("script_name")  query = spli