开发者

Classic Asp Extract Date in a text file

开发者 https://www.devze.com 2023-04-11 10:48 出处:网络
I would like to know who can I retrieve the date from a file. This is how I open my file: Set fs=Server.CreateObject(\"Scripting.FileSystemObject\")

I would like to know who can I retrieve the date from a file.

This is how I open my file:

    Set fs=Server.CreateObject("Scripting.FileSystemObject")

    Set f=fs.OpenTextFile(Server.MapPath("checkno_2211.html"), 1)
'Need something here to find the first date MM/DD/YYYY in the file
    f.Close

    Set f=Nothing
    Set fs=Nothing

The code above will open the .html file now I would like to find the first date that is in that file but I don't know how to do it. :-(

The .html file will have multiple dates in it, but I only need to grab the first one. The html and format of the date is like this:

<TD class="auto-style32" style="height: 31px">
Date:
 10/7/2011</TD>

The source code of the .html file is

        <HTML>
        <HEAD>
        <script SRC="include/general.js" language="javascript" type="text/javascript"></script>
        <style type="text/css">
        textarea { 
font-size: 14px;
font-weight: bold;
font-family: Arial;
}

.style1 {
    text-align: center;
}
.style2 {
    border-style: solid;
    border-width: 1px;
}
.style3 {
    color: #FFFFFF;
    background-color: #000000;
}
.style4 {
    background-color: #000000;
}
.style5 {
    color: #FFFFFF;
}
.style7 {
    vertical-align: text-bottom;
}
.style8 {
    font-family: Arial, Helvetica, sans-serif;
}
.style9 {
    background-color: #C0C0C0;
}
.style10 {
    vertical-align: middle;
}

        .auto-style30 {
            text-align: center;
            margin-left: 0px;
        }

        .auto-style32 {
            text-align: left;
            border-bottom-style: solid;
            border-bottom-width: 1px;
        }

        .auto-style35 {
            background-color: #000000;
        }
        .auto-style36 {
            border-top-style: solid;
            border-top-width: 1px;
        }

        </style>

<script language="javascript" type="text/javascript">
function GetURL_Alpha(){
document.getElementById("currentURL").value= location.href;
}
</script>

        <script SRC="include/general.js" language="javascript" type="text/javascript"></script>
        </HEAD>
        <BODY onload="printIt();GetURL_Alpha();" style="margin: 0 5">



<input name="currentURL" ID="currentURL" type="hidden" style="width: 1528px">

<CENTER>


<head>
<style type="text/css">
.auto-style36 {
    text-align: center;
}
</style>
</head>

    <TABLE border=0 style="width: 100%">
    <TR>
        <TD class="auto-style36">
        <font face="Century Gothic">
        <img src="logopro2.jpg"><BR>
            </font>
            <strong>
            <font face="Century Gothic" size="1">111 Test Main St Los Angeles, 
        CA 12345 </font></strong><font face="Century Gothic" size="1">
        <strong><BR>
            </strong>
            </font> <STRONG><FONT face="Century Gothic" size=1>PHONE: (888) 111-2222&nbsp;&nbsp;&nbsp;&nbsp;FAX: (877) 
        111-2233</FONT></STRONG>
        <br><br>
            </TD>
    </TR>
    </TABLE>
    </CENTER>
<table style="width: 100%">
<tr>
<td style="width: 408px"><font face="Arial">
<strong>
<h3 class="auto-style30" style="width: 492px">
FULL NAME<BR>
123 Test Ave<BR>
MIAMI, FL<BR>
</h3>
</strong>
</font>
&nbsp;</td>
<td>
</td>
<td>
&nbsp;</td>
</tr>
</table>

            <P align = center>
            <FONT face="Comic Sans MS" size=5><span class="style8">
<HR>
            <P align=center>
            <TABLE border开发者_如何学C=0 style="width: 100%" cellspacing="0">
                <tr>
            <FONT face="Comic Sans MS" size=5><span class="style8">
                <TD class="auto-style32" style="height: 31px">
                    Date:
                     10/7/2011</TD>
                <td style="height: 31px">Name:&nbsp;Someone</td>
                    <td class="style1" colspan="2" style="height: 31px">
            <FONT face="Comic Sans MS" size=5><span class="style8">
                    <strong>STATEMENT</strong></td>
                <TD colspan=3 align=right style="height: 31px">
                    Check #: 11008 
                </TD>
                    </span></font>
                </tr>
            <TR>
                <TD colspan=7 align=center class="auto-style35">
                    <span class="style5"></span>
                    <STRONG><FONT face="Arial" size=2 color="white">
                    <img src="more_images/ContainerRed.png" class="style10"> 
                    MORE INFORMATION</FONT></STRONG>                
                </TD>
            </TR>   

As always, Thanks for any help...


You could try something like this -

Dim ParseDate, NextLineIsDate 
NextLineIsDate = False
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
set fs = fso.OpenTextFile(Server.MapPath("Saved\checkno_2211.html"), 1, true) 
Do Until fs.AtEndOfStream 
    If NextLineIsDate Then
       ParseDate = Replace(Replace(fs.ReadLine," ",""),"</TD>","")
       Exit Do
    End If
    If Instr(fs.ReadLine,"Date:") > 0 Then NextLineIsDate = True
Loop 
Response.Write ParseDate 
fs.close: set fs = nothing 

The code above should output the date you're searching for to the screen.

This will work providing the text Date: only appears directly above dates in your text file. If it doesn't you might need some thing more complicated but it's hard to tell without seeing all the contents of your file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号