使用FSO修改文件特定内容的函数

使用FSO修改文件特定内容的函数function FSOchange(filename,Target,String)Dim objFSO,objCountFile,FiletempDataSet objFSO = Server.CreateObject(“Scripting.FileSystemObject”)Set objCountFile = objFSO.OpenTextFile(Server.MapPath(fil

大家好,又见面了,我是你们的朋友全栈君。function FSOchange(filename,Target,String)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FiletempData = objCountFile.ReadAll

objCountFile.Close

FiletempData=Replace(FiletempData,Target,String)

Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

objCountFile.Write FiletempData 

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

””使用FSO读取文件内容的函数

function FSOFileRead(filename)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FSOFileRead = objCountFile.ReadAll

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

””使用FSO读取文件某一行的函数

function FSOlinedit(filename,lineNum)

if linenum < 1 then exit function

dim fso,f,temparray,tempcnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

set f = nothing

temparray = split(tempcnt,chr(13)&chr(10))

if lineNum>ubound(temparray)+1 then

  exit function

else

  FSOlinedit = temparray(lineNum-1)

end if

end if

end function

””使用FSO写文件某一行的函数

function FSOlinewrite(filename,lineNum,Linecontent)

if linenum < 1 then exit function

dim fso,f,temparray,tempCnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

temparray = split(tempcnt,chr(13)&chr(10))

if lineNum>ubound(temparray)+1 then

  exit function

else

  temparray(lineNum-1) = lineContent

end if

tempcnt = join(temparray,chr(13)&chr(10))

set f = fso.createtextfile(server.mappath(filename),true)

f.write tempcnt

end if

f.close

set f = nothing

end function

””使用FSO添加文件新行的函数

function FSOappline(filename,Linecontent)

dim fso,f

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),8,1)

f.write chr(13)&chr(10)&Linecontent

f.close

set f = nothing

end function

””读文件最后一行的函数

function FSOlastline(filename)

dim fso,f,temparray,tempcnt

set fso = server.CreateObject(“scripting.filesystemobject”)

if not fso.fileExists(server.mappath(filename)) then exit function

set f = fso.opentextfile(server.mappath(filename),1)

if not f.AtEndofStream then

tempcnt = f.readall

f.close

set f = nothing

temparray = split(tempcnt,chr(13)&chr(10))

  FSOlastline = temparray(ubound(temparray))

end if

end function

‘还有,创建文件夹:

sub CreateFolder(Foldername)

Set afso = Server.CreateObject(“Scripting.FileSystemObject”)

  if afso.folderexists(server.mappath(Foldername))=true then

  else

   afso.createfolder(server.mappath(foldername))

  end if

set afso=nothing

end sub

‘用法,createfolder(foldername)

遍历目录以及目录下文件的函数

function bianli(path)

set fso=server.CreateObject(“scripting.filesystemobject”) 

on error resume next

set objFolder=fso.GetFolder(path)

set objSubFolders=objFolder.Subfolders

for each objSubFolder in objSubFolders 

nowpath=path + “/” + objSubFolder.name

Response.Write nowpath

set objFiles=objSubFolder.Files

for each objFile in objFiles

Response.Write “<br>—”

Response.Write objFile.name

next

Response.Write “<p>”

bianli(nowpath)’递归

next 

set objFolder=nothing

set objSubFolders=nothing

set fso=nothing

end function

%>

<%

‘bianli(“d:”) ‘遍历d:盘

%>

<%

‘替换指定文件内字符串的函数

function FSOlineedit(filename,Target,String)

Dim objFSO,objCountFile,FiletempData

Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)

Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)

FiletempData = objCountFile.ReadAll

objCountFile.Close

FiletempData=Replace(FiletempData,Target,String)

    Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

objCountFile.Write FiletempData 

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function

response.write FSOlineedit(“test.txt”,”世界”,”明天是一个好天去”)

%>

保持刷新文本框中的值

<HTML>

<HEAD>

<META NAME=”save” CONTENT=”history”>

<STYLE>

   .saveHistory {behavior:url(#default#savehistory);}

</STYLE>

<title>保持刷新文本框中的值</title></HEAD>

<BODY>

<INPUT class=saveHistory type=text id=oPersistInput>

</BODY>

</HTML>

ASP中连接数据库的5种方法

ASP中连接数据库的5种方法 

(01-3-30 199) 

from: chinaasp.com by caoli 

第一种 – 这种方法用在ACCESS中最多 

strconn = “DRIVER=Microsoft Access Driver (*.mdb);DBQ=” & Server.MapPath(“aspfree.mdb”) 

set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第二种-这种方法用在SQL SERVER中多 

strconn = “Driver={SQL 

Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name 

set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第三种 

strconn=”Driver={MicrosoftAccessDriver(*.mdb)};” &_ 

“DBQ=F:/Inetpub/wwwroot/somedir/db1.mdb;DefaultDir=f:/Inetpub/wwwroot/somedir;uid=LoginID;” &_ 

“pwd=Password;DriverId=25;FIL=MSAccess;” set conn = server.createobject(“adodb.connection”) 

conn.open strconn 

第四种运用系统数据源 

The following uses a Data Source Name: 

set conn = server.createobject(“adodb.connection”) 

conn.open “Example” 

第五种运用ODBC数据源,前提是你必须在控制面板的ODBC中设置数据源 

set rs = server.createobject(“adodb.recordset”) 

rs.open “tblname”, “DSNName”, 3, 3 

汉字判断(js判断)

for(i=0;i<realname.length;i++){

  char=realname.charCodeAt(i);  

  if(!(char>255)){  

   alert(“真实姓名应为汉字!”);

   userform.realname.focus();

   return false;

   }

  }

”身份证真伪

”id 省份证号

”birthday生日,yyyy-mm-dd格式

”sex性别,值为”男:1″,”女:0″

id = “460102800925121”

birthday = “1980-09-25”

sex = 1 

IF idcard_check(id,birthday,sex) Then

   response.write “不错”

else

   response.write “**”

End if

Function idcard_check(id,birthday,sex)

If len(id)<>15 and len(id)<>18 then

    idcard_check=false

    Exit Function

Else

    For i=1 to len(id)

       temp=mid(id,i,1)

       If temp<“0″ or temp>”9” Then

           idcard_check=False

           Exit Function

       End if

    Next

    bdl=left(birthday,4) & mid(birthday,6,2) & mid(birthday,9,2)

    bds=mid(birthday,3,2) & mid(birthday,6,2) & mid(birthday,9,2)

    If len(id)=15 Then

        If mid(id,7,6)<>bds Then

            idcard_check=False

            Exit Function

        End if

        If int(mid(id,15,1)) Mod 2 = 1 And sex=1 Then

            idcard_check=True

            Exit Function

  ElseIf int(mid(id,15,1)) Mod 2 = 0 And sex=0 Then

            idcard_check=True

            Exit Function

  Else

      idcard_check=False

            Exit Function

        End if

    Else

        If mid(id,7,8)<>bdl Then

            idcard_check=False

            Exit Function

        End if

        If int(mid(id,17,1)) Mod 2 = 1 And sex=1 Then

            idcard_check=False

            Exit Function

  ElseIf int(mid(id,17,1)) Mod 2 = 0 And sex=0 Then

            idcard_check=False

            Exit Function

  Else

   idcard_check=False

            Exit Function

        End if

    End if

End if

idcard_check=True

End function

11=”北京”

12=”天津”

13=”河北”

14=”山西”

15=”内蒙古”

21=”辽宁”

22=”吉林”

23=”黑龙江”

31=”上海”

32=”江苏”

33=”浙江”

34=”安徽”

35=”福建”

36=”江西”

37=”山东”

41=”河南”

42=”湖北”

43=”湖南”

44=”广东”

45=”广西”

46=”海南”

50=”重庆”

51=”四川”

52=”贵州”

53=”云南”

54=”西藏”

61=”陕西”

62=”甘肃”

63=”青海”

64=”宁夏”

65=”新疆”

71=”台湾”

81=”香港”

82=”澳门”

91=”国外”

生成一个不重复的随即数字

Sub CalCaPiao()

Dim strCaiPiaoNoArr() As String

Dim strSQL As String

Dim strCaiPiaoNo As String

strCaiPiaoNo = “01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33”

Dim StrTempArr(7) As String

Dim strZhongJiangArr(7) As String

strCaiPiaoNoArr = Split(strCaiPiaoNo, “,”)

Dim intRand As Integer

Dim i As Integer

Dim j As Integer

i = 0

Dim find As Boolean

Do While True

find = False

Randomize

intRand = Int((33 * Rnd) + 1)

For j = 0 To i – 1

If StrTempArr(j) = CStr(intRand) Then

find = True

End If

Next

If Not find Then

StrTempArr(j) = CStr(intRand)

strZhongJiangArr(i) = CStr(intRand)

‘Text1(i) = strZhongJiangArr(i)

i = i + 1

If i = 7 Then

Exit Do

End If

End If

Loop

End Sub

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/138663.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【整理】IDEA优化措施

    【整理】IDEA优化措施IDEA优化措施:包括快捷键、版本管理、语法规则检查、插件推荐、运行配置等

    2022年5月21日
    105
  • 业务测试用例模版与大数据测试用例模板

    业务测试用例模版与大数据测试用例模板前言:分享下业务测试用例模版与大数据测试用例模板业务测试用例模版与大数据测试用例模板一、业务测试用例模板二、业务测试用例模板一、业务测试用例模板需要下载模板请点击:业务测试用例模板下载二、业务测试用例模板需要下载模板请点击:大数据测试用例模板下载…

    2022年7月17日
    14
  • 史上最简单的SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)

    史上最简单的SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)

    2022年4月2日
    36
  • SQL经典语句大全及应用示例汇总

    SQL经典语句大全及应用示例汇总SQL经典语句大全及应用示例汇总无论您是一位SQLsever的新手,或是一位只是需要对SQL复习一下的资料仓储业界老将,您就来对地方了。本期专题精选了SQl语句、SQL语法、实例和教程等经典相关资源,助您SQL语句学习快速入门,让您一次看个够。可以下载附件留存~资源名称资源地址SQL语句大全【经典教程】…

    2022年5月15日
    33
  • mysql左连接查询

    mysql左连接查询mysql左连接查询左连接查询:以左表为主表,右表为从表,查询符合条件的数据1.当右表中数据匹配不到时展示为空例:左表两条数据,按条件匹配到右表一条数据且匹配左表第一条,结果展示两条数据,且第二条数据右表中的字段全部为null2.当匹配到右表的数据为多条时,左表数据会重复展示,不会自动合并例:左表数据一条,按条件匹配到右表数据三条,结果展示三条数据,左表数据均相同,右表数据不同…

    2022年6月3日
    55
  • java中的onresume_android onCreate onResume中获取 View 宽高为0分析

    java中的onresume_android onCreate onResume中获取 View 宽高为0分析1、问题测试xmlns:tools=”http://schemas.android.com/tools”android:layout_width=”match_parent”android:layout_height=”match_parent”>android:id=”@+id/btn”android:layout_width=”100dp”android:layout_height=”4…

    2022年6月2日
    48

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号