duxingzhe2005 2006-5-15 11:26
求助,关于fso的问题
编写一个C语言考试系统,需要把从数据库中读的c代码(是个带回车的字符串)写到文件中.
代码形式如下
#include <stdio.h>
main()
{
int i;
int j;
}
要求写到文件中也是这个形式,请问如何写?
写在服务端或客户端都可以.
冰霜之子 2006-5-15 11:27
利用.WriteLine方法:
<%
Set AFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set ATextStream = AFileSystemObject.CreateTextFile("C:\mulu\test.txt",true)
ATextStream.WriteLine("#include <stdio.h>")
ATextStream.WriteLine
ATextStream.WriteLine("main()")
ATextStream.WriteLine
ATextStream.Write("{")
ATextStream.WriteLine
ATextStream.WriteLine("int i;")
ATextStream.WriteLine
ATextStream.WriteLine("int j;")
ATextStream.WriteLine
ATextStream.Write("}")
ATextStream.Close
%>
xuyaoairen 2006-5-15 11:27
那么就不要用FSO来读取。先处理文章里的空格、回车之类字符再输出,给你一个函数:
<%
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
'result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>