使用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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 关于redis客户端连接不上

    关于redis客户端连接不上链接服务器的Redis(由于远程连接不上,使用服务器连接,也连接不上产生)Unabletoconnecttoremotehost:Connectionrefused连接不上,有可能是服务没有对外开放。1.修改redis配置:redis.conf.路径:C:\develop\Redis-x64-5.0.14\redis.windows.conf2.修改密码修改redis.conf配置文件(永久) #requirepassfoobaredrequire

    2022年6月10日
  • 穿女装上班的大厂程序员:我知道自己是个男生「建议收藏」

    穿女装上班的大厂程序员:我知道自己是个男生「建议收藏」本文转载自程序员技术“三流码农写UI,二流码农写架构,一流码农写算法,顶级码农穿女装。”——互联网圈子里,一直流传着这样一句无从考证的段子。程序员穿女装,是一个神秘而热门的话题。大部分人都曾经道听途说过相关的故事,也有人在网络上看过“女装大佬”的照片,比如曾经微博非官方举办过一次“程序员女装大赛”,引起过很多程序员的围观。但是生活里,似乎很少看到真实的女装程序员的事例。当小众文化、性别、和互联网的职业交融在一起,他们经历过什么样的故事,产生过什么样…

    2022年7月25日
  • 在微型计算机中1gb等于多少字节,1GB等于多少字节「建议收藏」

    在微型计算机中1gb等于多少字节,1GB等于多少字节「建议收藏」1GB=1073741824字节。1KB=1024字节1M=1024KB1G=1024MB一小组相邻的二进制数码称为字节。通常是8位作为一个字节。它是构成信息的一个小单位,并作为一个整体来参加操作,比字小,是构成字的单位。扩展资料:数据的存储是以“字节”(Byte)为单位,数据传输大多是以“位”(bit,又名“比特”)为单位,一个位就代表一个0或1(即二进制),每8个位(bit,简写为b)组成一个…

    2022年5月9日
  • 编程实现strstr函数「建议收藏」

    编程实现strstr函数「建议收藏」函数接口为:char*mystrstr(char*str1,char*str2)要求:在字符串str1中查找第一次出现字符串str2的位置,如果找到匹配的字符串,返回第一次匹配的指针,否则返回NULL。#include&lt;iostream&gt;usingnamespacestd;char*mystrstr(char*str1,char*str2){ char*p,*q;…

    2022年6月25日
  • googlenet网络模型简介_网络参考模型

    googlenet网络模型简介_网络参考模型一、GoogleNet模型简介  GoogleNet和VGG是2014年imagenet竞赛的双雄,这两类模型结构有一个共同特点是godeeper。跟VGG不同的是,GoogleNet做了更大胆的网络上的尝试而不是像VGG继承了Lenet以及AlexNet的一些框架,该模型虽然有22层,但大小却比AlexNet和VGG都小很多,性能优越。深度学习以及神经网络快速发展,人们容易通过更高性能的

    2022年8月14日
  • oracle11g下载地址_如何安装oracle10g数据库

    oracle11g下载地址_如何安装oracle10g数据库OracleDatabase10gRelease2(10.2.0.1.0)Enterprise/StandardEditionforMicrosoftWindows(32-bit)http://download.oracle.com/otn/nt/oracle10g/10201/10201_database_win32.ziphttp://download.ora

    2022年8月30日

发表回复

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

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