asp读取txt
我现在有read.txt,格式如下:1MikeJordanisabasketballstar.Ilike______verymuchAA.heB.hisC.himD.hi...
我现在有read.txt,格式如下:
1 Mike Jordan is a basketball star. I like______ very much A
A. he B. his C. him D. himself
1为编号,题后A为正确答案
怎么能把txt的读出,并且写到数据库,数据库格式为id(编号),question(题目),A(选项A),B(选项B),C(选项C),D(选项D),answer(答案)!!!
谢谢各位高手帮忙啊 展开
1 Mike Jordan is a basketball star. I like______ very much A
A. he B. his C. him D. himself
1为编号,题后A为正确答案
怎么能把txt的读出,并且写到数据库,数据库格式为id(编号),question(题目),A(选项A),B(选项B),C(选项C),D(选项D),answer(答案)!!!
谢谢各位高手帮忙啊 展开
1个回答
展开全部
whichfile=server.mappath("read.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.OpenTextFile(whichfile,1)
While Not txt.AtEndOfStream
rline =txt.ReadLine'读取一行
if left(rline,1)='A' then
b=split(rline," ",-1,1)'用空格截取序号
aa=b(1)
bb=b(3)
cc=b(5)
dd=b(7)
else
changdu=len(rline)'判断一行的长度
a=split(rline," ",-1,1)'用空格截取序号
id=trim(a(0))'用空格截取序号
changdu2=len(id)'序号长度
question=mid(rline,changdu2,changdu-changdu1-1)'截取题目
answer=right(rline,1)
end if
sql="insert into "&表&"("id,question,answer,a,b,c,d) values('"&id&"','"&question&"','"&answer&"'&"','"&a&"','"&"','"&aa&"','"&"','"&bb&"','"&"','"&cc&"','"&"','"&dd&"','")"
conn.execute(sql)
语法可能有错,你自己调试,给你个思路
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.OpenTextFile(whichfile,1)
While Not txt.AtEndOfStream
rline =txt.ReadLine'读取一行
if left(rline,1)='A' then
b=split(rline," ",-1,1)'用空格截取序号
aa=b(1)
bb=b(3)
cc=b(5)
dd=b(7)
else
changdu=len(rline)'判断一行的长度
a=split(rline," ",-1,1)'用空格截取序号
id=trim(a(0))'用空格截取序号
changdu2=len(id)'序号长度
question=mid(rline,changdu2,changdu-changdu1-1)'截取题目
answer=right(rline,1)
end if
sql="insert into "&表&"("id,question,answer,a,b,c,d) values('"&id&"','"&question&"','"&answer&"'&"','"&a&"','"&"','"&aa&"','"&"','"&bb&"','"&"','"&cc&"','"&"','"&dd&"','")"
conn.execute(sql)
语法可能有错,你自己调试,给你个思路
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询