编写一个C语言考试系统,需要把从数据库中读的c代码(是个带回车的字符串)写到文件中.
代码形式如下
#include
1<stdio.h>
2main()
3{
4int i;
5int j;
6}
7要求写到文件中也是这个形式,请问如何写?
8写在服务端或客户端都可以.
9
10
11\---------------------------------------------------------------
12
13利用.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
1
2\---------------------------------------------------------------
3
4那么就不要用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
1
2\---------------------------------------------------------------
3
4http://search.csdn.net/expert/topic/3/301/2002/10/14/1094170.htm</stdio.h></stdio.h>