当前位置: 首页 > 技术文档 > 刘松Class(Cls_Liusong)常用功能函数类

刘松Class(Cls_Liusong)常用功能函数类

来源:LCMS企业网站管理系统 发表时间:2010-5-17 22:51:16 浏览次数:

core/cls_liusong.asp 领略刘松Class魅力,版本 v4.4。

缓存功能函数

  • <Property> {String} Cls_LiuSong.CacheName
    定义缓存命名空间
    ls.CacheName = "cache"
    Response.Write ls.CacheName 'Returns: cache
    默认值:
    cache

  • <Property> {Integer} Cls_LiuSong.ReloadTime
    缓存重新加载时间间隔:分钟
    ls.ReloadTime = 28800
    Response.Write ls.ReloadTime 'Returns: 28800
    默认值:
    28800

  • <Property> {String} Cls_LiuSong.Name
    定义缓存变量名称
    ls.Name = "lcms"

  • <Property> {Variant} Cls_LiuSong.Value
    缓存赋值及取值
    ls.Value = "LCMS内容管理系统"
    Response.Write ls.Value 'Returns: LCMS内容管理系统

错误功能函数

  • <Property> {String} Cls_LiuSong.Debug
    开发者调试模式:默认关闭。 (v4.4)
    ls.Debug = True

  • <Property> {String} Cls_LiuSong.ErrCount
    获取运行到当前错误发生次数。 (v4.4)
    Response.Write ls.ErrCount

  • <Sub> Cls_LiuSong.ErrMsg (String)
    输出错误信息:String定制错误信息。 (v4.4)
    ls.ErrMsg "数据库操作错误!"

  • <Sub> Cls_LiuSong.WarnMsg (String)
    输出警告信息:String定制警告信息。 (v4.4)
    ls.WarnMsg "缺少上传组件!"

  • <Sub> Cls_LiuSong.PreCode (String1, String2)
    输出一段代码:String1代码标题,String2代码。 (v4.4)
    ls.WarnMsg "频道对象", "Dim channel"

常用功能函数

  • <Function> {Integer} Cls_LiuSong.Length (String)
    字符串长度计算函数,汉字等双字节字符算长度为2
    Response.Write ls.Length("LCMS内容管理系统") 'Returns: 12
    String 值为空:
    -1

  • <Function> {Integer} Cls_LiuSong.InStrCount (String1, String2)
    计算String2在String1中出现的次数
    Response.Write ls.InStrCount("喜欢上LCMS内容管理系统", "CMS") 'Returns: 1
    String1 或 String2 值为空:
    -1

  • <Sub> Cls_LiuSong.Redirect (String, URL)
    弹出JS警告框并输出JS跳转
    ls.Redirect "喜欢上LCMS内容管理系统", "http://k88.cn/"
    URL 特定值为 "back", "reload", "close":
    back = 返回前一页, reload = 刷新页面, close = 关闭当前页
    String 值为空, URL 值不为空:
    仅输出JS跳转
    String 值不为空, URL 值为空:
    仅输出JS警告
    String 值为空, URL 值为空:
    调用失效

  • <Sub> Cls_LiuSong.Location (String, URL)
    输出JS指定窗体打开链接地址:String为窗体名,可以为JS Window Object,如self, top, parent
    ls.Location "top", "http://.k88.cn/"

  • <Sub> Cls_LiuSong.Confirm (String, URL1, URL2)
    输出JS确认对话框:String为提示信息,URL1为选“确定”跳转地址, URL2为选“取消”跳转地址
    ls.Confirm "确认要下载LCMS内容管理系统吗?", "http://.k88.cn/download/", ""

    URL1 值为空:
    选择“确定”不跳转
    URL2 值为空:
    选择“取消”不跳转:
  • <Function> {String} Cls_LiuSong.HTMLEncode (String)
    HTML编码函数
    Response.Write ls.HTMLEncode("<a href=""http://k88.cn"" target=""_blank"">LCMS内容管理系统</a>")
    'Returns: &lt;a href=&quot;http://k88.cn&quot; target=&quot;_blank&quot;&gt;LCMS内容管理系统&lt;/a&gt;

  • <Function> {String} Cls_LiuSong.Text (String)
    Text编码函数,转换HTML标签符号以用于编辑框
    Response.Write ls.Text("<a href=""http://k88.cn"" target=""_blank"">LCMS内容管理系统</a>")
    'Returns: &lt;a href=&quot;http://k88.cn&quot; target=&quot;_blank&quot;&gt;LCMS内容管理系统&lt;/a&gt;

  • <Function> {String} Cls_LiuSong.LeachHtml (String)
    去除字符串中的HTML标签内容
    Response.Write ls.LeachHtml("<a href=""http://k88.cn"" target=""_blank"">LCMS内容管理系统</a>") 'Returns: LCMS内容管理系统

  • <Function> {String} Cls_LiuSong.LeachDirtyChar (String)
    去除字符串多余的空格、缩进、空行等
    Response.Write ls.LeachDirtyChar("Hello    LCMS!") 'Returns: Hello LCMS!

  • <Function> {Variant} Cls_LiuSong.CData (Variant, Integer)
    强制转换函数,在数据处理中起到至关重要的作用
    'Integer 为 0, 将 Variant 转换为 Bit(0|1)
    Response.Write ls.CData(2, 0) 'Returns: 0
    默认值:
    0
    'Integer 为 1, 将 Variant 转换为 Byte(0 ~ 255)
    Response.Write ls.CData("1", 1) 'Returns: 1
    默认值:
    0
    'Integer 为 2, 将 Variant 转换为 Integer(-32,768 ~ 32,767)
    Response.Write ls.CData("123456", 0) 'Returns: 0
    默认值:
    0
    'Integer 为 3, 将 Variant 转换为 Long(-2,147,483,648 ~ 2,147,483,647)
    Response.Write ls.CData(-123456, 0) 'Returns: -123456
    默认值:
    0
    'Integer 为 4, 将 Variant 转换为 Currency(-922,337,203,685,477.5808 ~ 922,337,203,685,477.5807)
    Response.Write ls.CData(6.8272, 0) 'Returns: 6.8272
    默认值:
    0
    'Integer 为 5, 将 Variant 转换为 Date
    Response.Write ls.CData("2010-5-12", 0) 'Returns: 2010-5-12
    默认值:
    Now()
    'Integer 为 6, 将 String 转换为 SQL 查询字符串
    Response.Write ls.CData("'LCMS'", 0) 'Returns: ''LCMS''
    默认值:
    Empty
    'Integer 为 7, 将 String 转换为 SQL 模糊查询字符串
    Response.Write ls.CData("LCMS' 100%", 0) 'Returns: LCMS'' 100[%]
    默认值:
    Empty
    'Integer 为 Empty, 将 Variant 转换为 String
    Response.Write ls.CData("Hello    LCMS!", "") 'Returns: Hello    LCMS!
    默认值:
    Empty

  • <Function> {String} Cls_LiuSong.CCode (String1, String2)
    判断String1是否符合由三位数字为一组组成的字符串
    Response.Write ls.CCode("12345", "001001") 'Returns: 001001
    默认值:
    String2

  • <Function> {String} Cls_LiuSong.CLike (String1, String2, Integer)
    转换SQL多关键字模糊查询字符串:String1字段名,String2关键字,Integer关键字最大拆分次数
    Response.Write ls.CLike("lcms", "内容 管理 系统", 3) 'Returns: lcms like '%内容%' and lcms like '%管理%' and lcms like '%系统%'
    默认值:
    1 = 1

  • <Function> {String} Cls_LiuSong.CPattern (String)
    转换正则表达式保留字符
    Response.Write ls.CPattern("(lcms)") 'Returns: \(lcms\)
    默认值:
    Empty

  • <Function> {Boolean} Cls_LiuSong.IsInArray (Array, String)
    判断字符串是否出现在数组中
    Response.Write ls.IsInArray({"lcms","内容管理系统"}, "lcms") 'Returns: True
    默认值:
    False

  • <Function> {String} Cls_LiuSong.RepeatString (String, Integer)
    重复字符串函数
    Response.Write ls.RepeatString({"lcms内容管理系统", 3}, "lcms") 'Returns: lcms内容管理系统lcms内容管理系统lcms内容管理系统
    默认值:
    Empty

  • <Function> {String} Cls_LiuSong.FixContent (String1, String2, Integer)
    字符串截取函数:String1需要截取的字符串,String2边界字符串,Integer截取方式
    'Integer 为 1, 截取String1 中第一个String2 后面的字符
    Response.Write ls.FixString("Hello LCMS!", "L", 1) 'Returns: CMS!
    'Integer 为 2, 截取String1 中第一个String2 后面的字符包括String2
    Response.Write ls.FixString("Hello LCMS!", "L", 2) 'Returns: LCMS!
    'Integer 为 3, 截取String1 中第一个String2 前面的字符
    Response.Write ls.FixString("Hello LCMS!", "L", 3) 'Returns: Hello 
    'Integer 为 4, 截取String1 中第一个String2 前面的字符包括String2
    Response.Write ls.FixString("Hello LCMS!", "L", 4) 'Returns: Hello L
    'Integer 为 5, 截取String1 中最后一个String2 后面的字符
    Response.Write ls.FixString("Hello LCMS!", "l", 5) 'Returns: o LCMS!
    'Integer 为 6, 截取String1 中最后一个String2 后面的字符括String2
    Response.Write ls.FixString("Hello LCMS!", "l", 6) 'Returns: lo LCMS!
    'Integer 为 7, 截取String1 中最后一个String2 前面的字符
    Response.Write ls.FixString("Hello LCMS!", "l", 7) 'Returns: Hel
    'Integer 为 8, 截取String1 中最后一个String2 前面的字符括String2
    Response.Write ls.FixString("Hello LCMS!", "l", 8) 'Returns: Hell
    默认值:
    Empty

  • <Function> {Currency} Cls_LiuSong.FCur (Currency)
    货币类型转换函数:使用三位一组的逗号","分割,小数点后保留2位
    Response.Write ls.FCur(123456) 'Returns: 123,456.00
    默认值:
    0.00

  • <Property> {String} Cls_LiuSong.IP
    获得访问者的IP地址
    Response.Write ls.IP 'Returns: 127.0.0.1

  • <Property> {String} Cls_LiuSong.ActForIP
    获得访问者的代理IP地址
    Response.Write ls.ActForIP 'Returns: 127.0.0.1
    默认值:
    Empty

  • <Function> {String} Cls_LiuSong.FormatIP (String)
    将IP地址格式化为127.000.000.001格式
    Response.Write ls.FormatIP("127.0.0.1") 'Returns: 127.000.000.001
    默认值:
    Empty

  • <Function> {Boolean} Cls_LiuSong.IsObj (Variant)
    判断数据是否为对象类型。
    Response.Write ls.IsObj(ls) 'Returns: True
    默认值:
    Empty

  • <Function> {Array} Cls_LiuSong.ArraySort (Array)
    数组数据排序
    Response.Write ls.ArraySort 'Returns: ZZ
    默认值:
    Empty

  • <Function> {Variant} Cls_LiuSong.IIf (expression, truepart, falsepart)
    三元运算符:expression成立返回truepart,反之返回falsepart。 (v4.4)
    Response.Write ls.IIf(1=1, True, False) 'Returns: True

  • <Function> {Variant} Cls_LiuSong.IfThen (expression, truepart)
    条件运算:expression成立返回truepart,反之返回空字符串。 (v4.4)
    Response.Write ls.IfThen(1=1, True) 'Returns: True

  • <Function> {Variant} Cls_LiuSong.IfHas (part, falsepart)
    条件运算:part有效返回自身,无效返回falsepart。 (v4.4)
    Response.Write ls.IfHas("lcms", "cms") 'Returns: lcms

  • <Function> {Boolean} Cls_LiuSong.IsN (Variant)
    判断数据是否是无效值:空字符串,空数组,空对象或注销后的对象。 (v4.4)
    Response.Write ls.IsN("") 'Returns: True

  • <Function> {Boolean} Cls_LiuSong.Has (Variant)
    判断数据是否是有效值:与IsN相反。 (v4.4)
    Response.Write ls.Has("") 'Returns: False

  • <Function> {String} Cls_LiuSong.CLeft (expression, delimiter)
    拆分字符串:获得expression中,分隔符delimiter左侧的字符串。 (v4.4)
    Response.Write ls.CLeft("LCMS-jianjie", "-") 'Returns: LCMS

  • <Function> {String} Cls_LiuSong.CRight (expression, delimiter)
    拆分字符串:获得expression中,分隔符delimiter右侧的字符串。 (v4.4)
    Response.Write ls.CRight("LCMS-jianjie", "-") 'Returns: jianjie

  • <Function> {Boolean} Cls_LiuSong.Test (expression, pattern)
    数据验证:定制类型(date, number, idcard, english, chinese, username, email, int, double, price, zip, qq, phone, mobile, url, domain, ip)。 (v4.4)
    Response.Write ls.Test(1234, "int") 'Returns: True

  • <Function> {String} Cls_LiuSong.ToDictionary (options)
    将JSON格式的options转换成Scripting.Dictionary对象。 (v4.4)
    Dim objOption
    Set objOption = ls.ToDictionary("{""width"":""100px;"",""height"":""100px""}")

Form表单功能函数

  • <Property> {Boolean} Cls_LiuSong.CheckReferer
    验证数据来源,非本域提交数据返回False。 (v4.4)
    If ls.CheckReferer Then
        ...
    End If

  • <Sub> Cls_LiuSong.FormRadio (String1, String2, Integer1, Integer2)
    自动生成表单Radio:将以竖线分割的String1拆分成选项,String2为表单名称,Integer1为默认值,Integer2每行选项数。
    ls.FormRadio "|女|男", "Gender", 1, 4

  • <Sub> Cls_LiuSong.FormCheckbox (String1, String2, Integer1, Integer2)
    自动生成表单Checkbox:将以竖线分割的String1拆分成选项,String2为表单名称,Integer1为默认值,Integer2每行选项数。
    ls.FormCheckbox "功能强大|易用性|界面很酷|完全开源", "lcms", "0|1|2|3", 4

  • <Sub> Cls_LiuSong.FormSelect (String1, String2, Integer1, String3)
    自动生成表单Select:将以竖线分割的String1拆分成选项,String2为表单名称,Integer1为默认值,String3初始化选项。
    ls.CheckedLabel "很好|好|一般", "lcms", 0, "--LCMS评价--"

  • <Function> {String} Cls_LiuSong.CheckedLabel (String1, String2)
    被选中的值的文本内容
    Response.Write ls.CheckedLabel("很好|好|一般", "0") 'Returns: 很好
    默认值:
    Empty

  • <Sub> Cls_LiuSong.EditItem (String1, String2, String3)
    自动生成选项连接:将以竖线分割的String1拆分成以String2为链接地址的链接,String3为当前连接值
    '相关参数 ls.TypeReplacer = "#type#"
    ls.EditItem "未读|已读", "message.asp?s=" & ls.TypeReplacer, Request.QueryString("s")

内容采集功能函数

  • <Function> {String} Cls_LiuSong.GetHtml (String1, String2)
    内容采集函数:String1为采集地址URL,String2为POST参数
    Response.Write ls.GetHtml "http://k88.cn/", ""
    默认值:
    Empty

  • <Sub> Cls_LiuSong.SaveToFile (String1, String2, String3)
    内容采集保存功能:String1为采集地址URL,String2为POST参数,String3为保存在本地的物理路径
    Response.Write ls.SaveToFile "http://k88.cn/", "", Server.MapPath("/k88.html")

辅助函数

  • <Function> {String} Cls_LiuSong.URLDecode (String)
    URL解码函数
    Response.Write ls.URLDecode "http://k88.cn/" 'Returns:  http://k88.cn/
    默认值:
    Empty

正则表达式函数

  • <Property> {String} Cls_LiuSong.IgnoreCase
    设置正则表达式是否忽略大小写
    ls.IgnoreCase = True
    默认值:
    True

  • <Property> {String} Cls_LiuSong.Global
    设置正则表达式是否全局搜索
    ls.Global = True
    默认值:
    True

  • <Function> {String} Cls_LiuSong.RegExpReplace (String1, String2, String3)
    正则替换Replace:String1需要替换的字符串,String2正则表达式,String3替换字符串
    Response.Write ls.RegExpReplace("LCMS内容管理系统", "[^\x00-\xff]", "aa") 'Returns: LCMSaaaaaaaaaaaa

  • <Function> {Boolean} Cls_LiuSong.RegExpTest (String1, String2)
    正则验证Test:String1为待验证字串,String2为正则表达式
    Response.Write ls.RegExpTest("276359669", "^[1-9]\d{4, 9}$") 'Returns: True

  • <Function> {Object} Cls_LiuSong.RegExpMatch (String1, String2)
    正则匹配Match:String1为待匹配字串,String2为正则表达式
    Dim objMatch
    Set objMatch = ls.RegExpMatch("QQ:276359669", "[1-9]\d{4, 9}")

  • <Function> {String} Cls_LiuSong.RegExpFetch (String1, String2)
    正则匹配结果:String1为待匹配字串,String2为正则表达式
    Response.Write ls.RegExpFetch("QQ:276359669", "[1-9]\d{4, 9}") 'Returns: 276359669
    默认值:
    Empty

数据库操作函数

  • <Property> {Object} Cls_LiuSong.Connection
    设置或获得数据库连接对象
    '获得数据库连接对象
    Dim objConn
    Set objConn = ls.Connection
    '设置数据库连接对象
    ls.Connection = objConn

  • <Sub> Cls_LiuSong.SqlConnection (String1, String2, String3, String4)
    建立Sql2000数据库连接:String1服务器地址,String2数据库名称,String3登录名称,String4登录密码
    ls.SqlConnection "localhost", "lcms", "sa", ""

  • <Sub> Cls_LiuSong.Sql2005Connection (String1, String2, String3, String4)
    建立Sql2000数据库连接:String1服务器地址,String2数据库名称,String3登录名称,String4登录密码
    ls.SqlConnection "(local)", "lcms", "sa", ""

  • <Sub> Cls_LiuSong.OleDbConnection (String)
    建立Access数据库连接:String为Access数据库物理地址
    ls.OleDbConnection Server.MapPath("/data/#data.mdb")

  • <Sub> Cls_LiuSong.CloseDatabase
    关闭数据库连接
    ls.CloseDatabase

  • <Property> {String} Cls_LiuSong.QueryString
    获得当前页面查询字符串
    Response.Write ls.QueryString
    默认值:
    Empty

  • <Property> {String} Cls_LiuSong.ThisServer
    获得当前当前服务器地址
    Response.Write ls.ThisServer

  • <Property> {String} Cls_LiuSong.URL
    获得当前页面地址
    Response.Write ls.URL

  • <Property> {String} Cls_LiuSong.ShowSQL
    设置是否显示执行的SQL语句,用于查询调试使用
    ls.ShowSQL = True

  • <Property> {Integer} Cls_LiuSong.RecordsAffected
    获得前一条SQL影响的记录数(insert, update, delete)
    Response.Write ls.RecordsAffected
    默认值:
    0

  • <Property> {Integer} Cls_LiuSong.SqlCount
    获得当前执行的SQL语句数量
    Response.Write ls.SqlCount
    默认值:
    0

  • <Property> {Boolean} Cls_LiuSong.RecordCountCache
    是否启用缓存SQL统计语句值:仅在数据库分页时有效,一遍增加查询速度
    ls.RecordCountCache = False
    默认值:
    False

  • <Property> {Boolean} Cls_LiuSong.RecordDistinct
    是否启过滤重复记录集:暂时无效
    ls.RecordDistinct = False
    默认值:
    False

  • <Property> {Integer} Cls_LiuSong.PageNo
    获得当前分页页码
    Response.Write ls.PageNo
    默认值:
    1

  • <Property> {Integer} Cls_LiuSong.PageSize
    设置或获得每页记录数
    ls.PageSize = 40 '设置每页记录为40条
    Response.Write ls.PageSize '显示当前每页记录数

  • <Property> {Integer} Cls_LiuSong.RecordCount
    获得参与分页记录的总数(ls.Pagination执行后)
    Response.Write ls.RecordCount
    默认值:
    0

  • <Property> {Integer} Cls_LiuSong.PageCount
    获得参与分页记录的总数(ls.Pagination执行后)
    Response.Write ls.PageCount
    默认值:
    0

  • <Property> {Boolean} Cls_LiuSong.IsPageGo
    设置输出页码连接时,是否显示页码输入框
    ls.IsPageGo = False
    默认值:
    False

  • <Property> {Integer} Cls_LiuSong.MaxPage
    设置分页时最大页码:值为0时参数无效
    ls.MaxPage = 0
    默认值:
    0

  • <Function> {String} Cls_LiuSong.Clustering (String)
    返回一条SQL统计语句结果,同样适用于单字段查询
    Response.Write ls.Clustering("select count(*) from Articles")
    执行错误:
    -1

  • <Function> {String} Cls_LiuSong.RecordString (String1, String2, String3)
    将SQL语句查询的记录集生成字符串后返回:String1为SQL语句,String2为列分割符,String3为行分割符
    Response.Write ls.RecordString("select top 10 Title from Articles", "", ",")
    默认值:
    Empty

  • <Function> {Array} Cls_LiuSong.Execute (String)
    将SQL语句查询的记录集以二维数组方式返回
    Dim arrRecord
    arrRecord = ls.Execute("select ArticleID, Title from Articles") 'IsArray(arrRecord) = True 为成功

  • <Function> {Array} Cls_LiuSong.Pagination (String1, String2, String3, String4, String5)
    优化分页函数,将记录集以二维数据方式返回:String1为主键,String2为查询的字段,String3为查询From语句,String4为Where语句,String5为Order语句
    Dim arrRecord
    arrRecord = ls.Execute("ArticleID", "ArticleID, Title", "from Articles", "where Status = 1", "order by ArticleID desc") 'IsArray(arrRecord) = True 为成功

  • <Sub> {Array} Cls_LiuSong.PageList
    输出页码列表(ls.Pagination执行后)
    ls.PageList

文件与文件操作函数

  • <Function> {Boolean} Cls_LiuSong.MD (String)
    创建文件夹:String为文件夹物理路径
    Response.Write ls.MD(Server.MapPath("lcms"))
    默认值:
    False

  • <Function> {Boolean} Cls_LiuSong.RD (String)
    删除文件夹:String为文件夹物理路径。 (v4.4)
    Response.Write ls.RD(Server.MapPath("lcms"))
    默认值:
    False

  • <Function> {Boolean} Cls_LiuSong.Del (String)
    删除文件:String为文件物理路径
    Response.Write ls.Del(Server.MapPath("index.html"))
    默认值:
    False

Cookies操作函数

  • <Sub> Cls_LiuSong.SetCookie (name, key, value, options)
    设置Cookies:name为Cookies名称,key为键值可以为空,value为Cookies值,options为Cookies可选项。 (v4.4)
    ls.SetCookie "lcms", "ver", "1.2", "{""Expires"":""1440""}"

  • <Function> {Variant} Cls_LiuSong.Cookie (name, key)
    读取Cookies:name为Cookies名称,key为键值可以为空。 (v4.4)
    Response.Write ls.Cookie("lcms", "ver")

  • <Sub> Cls_LiuSong.RemoveCookie (name, key)
    清除Cookies。 (v4.4)
    ls.RemoveCookie "lcms", "ver"

  • <Sub> Cls_LiuSong.ClearCookies
    清除所有Cookies
    ls.ClearCookies